Merge branch 'lahwaacz-shift_ins'

This commit is contained in:
Florian Bruhin 2016-01-31 22:09:13 +01:00
commit b4a54822a0
8 changed files with 125 additions and 1 deletions

View File

@ -23,6 +23,9 @@ Added
- New `--quiet` argument for the `:debug-pyeval` command to not open a tab with
the results. Note `:debug-pyeval` is still only intended for debugging.
- The completion now matches each entered word separately.
- A new command `:paste-primary` got added to paste the primary selection, and
`<Shift-Insert>` got added as a binding so it pastes primary rather than
clipboard.
Changed
~~~~~~~

View File

@ -165,6 +165,7 @@ Contributors, sorted by the number of commits in descending order:
* Jonas Schürmann
* Panagiotis Ktistakis
* Jimmy
* Jakub Klinkovský
* skinnay
* error800
* Zach-Button

View File

@ -833,6 +833,7 @@ How many steps to zoom out.
|<<move-to-start-of-next-block,move-to-start-of-next-block>>|Move the cursor or selection to the start of next block.
|<<move-to-start-of-prev-block,move-to-start-of-prev-block>>|Move the cursor or selection to the start of previous block.
|<<open-editor,open-editor>>|Open an external editor with the currently selected form field.
|<<paste-primary,paste-primary>>|Paste the primary selection at cursor position.
|<<prompt-accept,prompt-accept>>|Accept the current prompt.
|<<prompt-no,prompt-no>>|Answer no to a yes/no prompt.
|<<prompt-yes,prompt-yes>>|Answer yes to a yes/no prompt.
@ -1046,6 +1047,10 @@ Open an external editor with the currently selected form field.
The editor which should be launched can be configured via the `general -> editor` config option.
[[paste-primary]]
=== paste-primary
Paste the primary selection at cursor position.
[[prompt-accept]]
=== prompt-accept
Accept the current prompt.

View File

@ -1307,6 +1307,31 @@ class CommandDispatcher:
except webelem.IsNullError:
raise cmdexc.CommandError("Element vanished while editing!")
@cmdutils.register(instance='command-dispatcher',
modes=[KeyMode.insert], hide=True, scope='window',
needs_js=True)
def paste_primary(self):
"""Paste the primary selection at cursor position."""
frame = self._current_widget().page().currentFrame()
try:
elem = webelem.focus_elem(frame)
except webelem.IsNullError:
raise cmdexc.CommandError("No element focused!")
if not elem.is_editable(strict=True):
raise cmdexc.CommandError("Focused element is not editable!")
clipboard = QApplication.clipboard()
if clipboard.supportsSelection():
sel = clipboard.text(QClipboard.Selection)
log.misc.debug("Pasting primary selection into element {}".format(
elem.debug_text()))
elem.evaluateJavaScript("""
var sel = '{}';
var event = document.createEvent('TextEvent');
event.initTextEvent('textInput', true, true, null, sel);
this.dispatchEvent(event);
""".format(webelem.javascript_escape(sel)))
def _clear_search(self, view, text):
"""Clear search string/highlights for the given view.

View File

@ -1324,7 +1324,8 @@ KEY_SECTION_DESC = {
"Since normal keypresses are passed through, only special keys are "
"supported in this mode.\n"
"Useful hidden commands to map in this section:\n\n"
" * `open-editor`: Open a texteditor with the focused field."),
" * `open-editor`: Open a texteditor with the focused field.\n"
" * `paste-primary`: Paste primary selection at cursor position."),
'hint': (
"Keybindings for hint mode.\n"
"Since normal keypresses are passed through, only special keys are "
@ -1495,6 +1496,7 @@ KEY_DATA = collections.OrderedDict([
('insert', collections.OrderedDict([
('open-editor', ['<Ctrl-E>']),
('paste-primary', ['<Shift-Ins>']),
])),
('hint', collections.OrderedDict([

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Paste primary selection</title>
</head>
<body>
<textarea id="qute-textarea"></textarea>
<textarea id="qute-textarea-noedit" readonly></textarea>
</body>
</html>

View File

@ -38,3 +38,16 @@ def skip_with_broken_clipboard(qtbot, qapp):
if clipboard.text() != "Does this work?":
pytest.skip("Clipboard seems to be broken on this platform.")
@bdd.when(bdd.parsers.parse('I set the text field to "{value}"'))
def set_text_field(quteproc, value):
quteproc.send_cmd(":jseval document.getElementById('qute-textarea').value "
"= '{}';".format(value))
@bdd.then(bdd.parsers.parse('the text field should contain "{value}"'))
def check_text_field(quteproc, value):
quteproc.send_cmd(":jseval console.log('text: ' + "
"document.getElementById('qute-textarea').value);")
quteproc.wait_for_js('text: ' + value)

View File

@ -170,3 +170,67 @@ Feature: Yanking and pasting.
history:
- active: true
url: http://localhost:*/data/hello3.txt
#### :paste-primary
Scenario: Pasting the primary selection into an empty text field
When selection is supported
And I open data/paste_primary.html
And I put "Hello world" into the primary selection
# Click the text field
And I run :hint all
And I run :follow-hint a
And I run :paste-primary
# Compare
Then the text field should contain "Hello world"
Scenario: Pasting the primary selection into a text field at specific position
When selection is supported
And I open data/paste_primary.html
And I set the text field to "one two three four"
And I put " Hello world" into the primary selection
# Click the text field
And I run :hint all
And I run :follow-hint a
# Move to the beginning and two words to the right
And I press the keys "<Home>"
And I press the key "<Ctrl+Right>"
And I press the key "<Ctrl+Right>"
And I run :paste-primary
# Compare
Then the text field should contain "one two Hello world three four"
Scenario: Pasting the primary selection into a text field with undo
When selection is supported
And I open data/paste_primary.html
# Click the text field
And I run :hint all
And I run :follow-hint a
# Paste and undo
And I put "This text should be undone" into the primary selection
And I run :paste-primary
And I press the key "<Ctrl+z>"
# Paste final text
And I put "This text should stay" into the primary selection
And I run :paste-primary
# Compare
Then the text field should contain "This text should stay"
Scenario: Pasting the primary selection without a focused field
When selection is supported
And I open data/paste_primary.html
And I put "test" into the primary selection
And I run :enter-mode insert
And I run :paste-primary
Then the error "No element focused!" should be shown
Scenario: Pasting the primary selection with a read-only field
When selection is supported
And I open data/paste_primary.html
# Click the text field
And I run :hint all
And I run :follow-hint s
And I put "test" into the primary selection
And I run :enter-mode insert
And I run :paste-primary
Then the error "Focused element is not editable!" should be shown