Skip to content

Commit

Permalink
String formatting, and macos next word shortcut
Browse files Browse the repository at this point in the history
Failing test: macos doesn't use ctrl-left for next word? uses meta-left?
  • Loading branch information
athompson673 authored Feb 28, 2025
1 parent 7006153 commit 6b77c84
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions spyder/plugins/editor/widgets/codeeditor/tests/test_multicursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Standard library imports
from inspect import cleandoc
import sys

# Third party imports
import pytest
Expand Down Expand Up @@ -754,50 +755,78 @@ def bar():
# TODO test killring
# TODO test undo/redo


def test_clipboard(codeeditor, qtbot):
# copy
codeeditor.set_text("one two\nthree four\nfive six\n")
codeeditor.set_text("one two\n"
"three four\n"
"five six\n")
call_shortcut(codeeditor, "add cursor down")
call_shortcut(codeeditor, "add cursor down")

ctrl = Qt.KeyboardModifier.ControlModifier
if sys.platform == "darwin":
ctrl = Qt.KeyboardModifier.MetaModifier
qtbot.keyClick(
codeeditor,
Qt.Key.Key_Right,
modifier=(
Qt.KeyboardModifier.ControlModifier |
Qt.KeyboardModifier.ShiftModifier
)
modifier=(ctrl | Qt.KeyboardModifier.ShiftModifier)
) # Shift-Ctrl-Right select up to next word
call_shortcut(codeeditor, "copy")
cb = QApplication.clipboard()
assert cb.text() == "one \nthree \nfive "
assert cb.text() == ("one \n"
"three \n"
"five ")
# cut
call_shortcut(codeeditor, "cut")
assert cb.text() == "one \nthree \nfive "
assert codeeditor.toPlainText() == "two\nfour\nsix\n"
assert cb.text() == ("one \n"
"three \n"
"five ")
assert codeeditor.toPlainText() == ("two\n"
"four\n"
"six\n")
# 1-n paste
click_at(codeeditor, qtbot, 13) # set single cursor at end of file
click_at(codeeditor, qtbot, 13) # set single cursor at end of file
call_shortcut(codeeditor, "paste")
assert codeeditor.toPlainText() == "two\nfour\nsix\none \nthree \nfive "
assert codeeditor.toPlainText() == ("two\n"
"four\n"
"six\n"
"one \n"
"three \n"
"five ")
# n-n paste
click_at(codeeditor, qtbot, 0) # set single cursor at start of file
click_at(codeeditor, qtbot, 0) # set single cursor at start of file
call_shortcut(codeeditor, "add cursor down")
call_shortcut(codeeditor, "add cursor down")
call_shortcut(codeeditor, "paste")
assert codeeditor.toPlainText() == "one two\nthree four\nfive six\none \nthree \nfive "
assert codeeditor.toPlainText() == ("one two\n"
"three four\n"
"five six\n"
"one \n"
"three \n"
"five ")
# n-m paste: number of cursors < lines in clipboard
codeeditor.set_text("\n\n\n\n")
click_at(codeeditor, qtbot, 0) # set single cursor at start of file
codeeditor.set_text("\n"
"\n"
"\n"
"\n")
click_at(codeeditor, qtbot, 0) # set single cursor at start of file
call_shortcut(codeeditor, "add cursor down")
call_shortcut(codeeditor, "paste")
assert codeeditor.toPlainText() == "one \nthree \n\n\n"
assert codeeditor.toPlainText() == ("one \n"
"three \n"
"\n"
"\n")
# n-m paste: number of cursors > lines in clipboard
codeeditor.set_text("\n\n\n\n")
click_at(codeeditor, qtbot, 0) # set single cursor at start of file
click_at(codeeditor, qtbot, 0) # set single cursor at start of file
call_shortcut(codeeditor, "add cursor down")
call_shortcut(codeeditor, "add cursor down")
call_shortcut(codeeditor, "add cursor down")
call_shortcut(codeeditor, "paste")
assert codeeditor.toPlainText() == "one \nthree \nfive \n\n"
assert codeeditor.toPlainText() == ("one one \n"
"three three \n"
"five \n"
"\n")

# TODO test enter inline array/table
# TODO test inspect current object
Expand Down

0 comments on commit 6b77c84

Please sign in to comment.