From e7d0039aca6f9a198742653e119f68ac82a0dc1a 2022-02-25 10:10:07 From: Matthias Bussonnier Date: 2022-02-25 10:10:07 Subject: [PATCH] Merge pull request #13540 from lucymcphail/master Improve auto_match for quotes --- diff --git a/IPython/terminal/shortcuts.py b/IPython/terminal/shortcuts.py index ea204f8..274f9b2 100644 --- a/IPython/terminal/shortcuts.py +++ b/IPython/terminal/shortcuts.py @@ -139,12 +139,24 @@ def create_ipython_shortcuts(shell): event.current_buffer.insert_text("{}") event.current_buffer.cursor_left() - @kb.add('"', filter=focused_insert & auto_match & following_text(r"[,)}\]]|$")) + @kb.add( + '"', + filter=focused_insert + & auto_match + & preceding_text(r'^([^"]+|"[^"]*")*$') + & following_text(r"[,)}\]]|$"), + ) def _(event): event.current_buffer.insert_text('""') event.current_buffer.cursor_left() - @kb.add("'", filter=focused_insert & auto_match & following_text(r"[,)}\]]|$")) + @kb.add( + "'", + filter=focused_insert + & auto_match + & preceding_text(r"^([^']+|'[^']*')*$") + & following_text(r"[,)}\]]|$"), + ) def _(event): event.current_buffer.insert_text("''") event.current_buffer.cursor_left() @@ -186,16 +198,6 @@ def create_ipython_shortcuts(shell): event.current_buffer.insert_text("{}" + dashes) event.current_buffer.cursor_left(len(dashes) + 1) - @kb.add('"', filter=focused_insert & auto_match & preceding_text(r".*(r|R)$")) - def _(event): - event.current_buffer.insert_text('""') - event.current_buffer.cursor_left() - - @kb.add("'", filter=focused_insert & auto_match & preceding_text(r".*(r|R)$")) - def _(event): - event.current_buffer.insert_text("''") - event.current_buffer.cursor_left() - # just move cursor @kb.add(")", filter=focused_insert & auto_match & following_text(r"^\)")) @kb.add("]", filter=focused_insert & auto_match & following_text(r"^\]"))