Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-145375: Fix bracketed paste in PyREPL isearch mode#145398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tanloong wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromtanloong:isearch-paste
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletionLib/_pyrepl/historical_reader.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@


isearch_keymap: tuple[tuple[KeySpec, CommandName], ...] = tuple(
[("\\%03o" % c, "isearch-end") for c in range(256) if chr(c)!="\\"]
[("\\%03o" % c, "isearch-end") for c in range(256) if chr(c)not in ("\\", "\x1b")]
+ [(c, "isearch-add-character") for c in map(chr, range(32, 127)) if c != "\\"]
+ [
("\\%03o" % c, "isearch-add-character")
Expand All@@ -45,6 +45,7 @@
(r"\C-c", "isearch-cancel"),
(r"\C-g", "isearch-cancel"),
(r"\<backspace>", "isearch-backspace"),
(r"\x1b[200~", "isearch-bracketed-paste"),
]
)

Expand DownExpand Up@@ -209,6 +210,21 @@ def do(self) -> None:
r.pop_input_trans()
r.dirty = True

class isearch_bracketed_paste(commands.Command):
def do(self) -> None:
r = self.reader
b = r.buffer
done = "\x1b[201~"
data = ""
while done not in data:
ev = r.console.getpending()
data += ev.data
paste_content = data.replace(done, "")
r.isearch_term += paste_content
r.dirty = True
if "".join(b[r.pos:r.pos+len(r.isearch_term)]) != r.isearch_term:
r.isearch_next()


@dataclass
class HistoricalReader(Reader):
Expand DownExpand Up@@ -245,6 +261,7 @@ def __post_init__(self) -> None:
isearch_backspace,
isearch_forwards,
isearch_backwards,
isearch_bracketed_paste,
operate_and_get_next,
history_search_backward,
history_search_forward,
Expand Down
38 changes: 38 additions & 0 deletionsLib/test/test_pyrepl/test_pyrepl.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1509,6 +1509,44 @@ def test_bracketed_paste_single_line(self):
output = multiline_input(reader)
self.assertEqual(output, input_code)

def test_bracketed_paste_in_isearch(self):
paste_start = "\x1b[200~"
paste_end = "\x1b[201~"

events = itertools.chain(
# Add some history
code_to_events("print('hello')\n"),
# Search for 'hello'
[
Event(evt="key", data="\x12", raw=bytearray(b"\x12")),
],
code_to_events(paste_start),
code_to_events("hello"),
code_to_events(paste_end),
[
Event(evt="key", data="\n", raw=bytearray(b"\n")),
Event(evt="key", data="\n", raw=bytearray(b"\n")),
],
[
Event(evt="key", data="\x12", raw=bytearray(b"\x12")),
],
# Search for 'world', which should not be found
code_to_events(paste_start),
code_to_events("world"),
code_to_events(paste_end),
[
Event(evt="key", data="\n", raw=bytearray(b"\n")),
Event(evt="key", data="\n", raw=bytearray(b"\n")),
],
)

reader = self.prepare_reader(events)
multiline_input(reader)
output = multiline_input(reader)
self.assertEqual(output, "print('hello')")
output = multiline_input(reader)
self.assertEqual(output, "")


@skipUnless(pty, "requires pty")
class TestDumbTerminal(ReplTestCase):
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Handle bracketed paste in :mod:`!_pyrepl` isearch mode.
Loading

[8]ページ先頭

©2009-2026 Movatter.jp