From a6a1d36300661b168da1ebff3bf52f2a0e982f26 2022-01-24 19:36:14 From: Gal B Date: 2022-01-24 19:36:14 Subject: [PATCH] Add missing auto_match flag in shortcuts.py This commit fixes issues where IPython inserts quotes after r or R regardless of context. --- diff --git a/IPython/terminal/shortcuts.py b/IPython/terminal/shortcuts.py index 6aab3d2..ea204f8 100644 --- a/IPython/terminal/shortcuts.py +++ b/IPython/terminal/shortcuts.py @@ -150,7 +150,9 @@ def create_ipython_shortcuts(shell): event.current_buffer.cursor_left() # raw string - @kb.add("(", filter=focused_insert & preceding_text(r".*(r|R)[\"'](-*)$")) + @kb.add( + "(", filter=focused_insert & auto_match & preceding_text(r".*(r|R)[\"'](-*)$") + ) def _(event): matches = re.match( r".*(r|R)[\"'](-*)", @@ -160,7 +162,9 @@ def create_ipython_shortcuts(shell): event.current_buffer.insert_text("()" + dashes) event.current_buffer.cursor_left(len(dashes) + 1) - @kb.add("[", filter=focused_insert & preceding_text(r".*(r|R)[\"'](-*)$")) + @kb.add( + "[", filter=focused_insert & auto_match & preceding_text(r".*(r|R)[\"'](-*)$") + ) def _(event): matches = re.match( r".*(r|R)[\"'](-*)", @@ -170,7 +174,9 @@ def create_ipython_shortcuts(shell): event.current_buffer.insert_text("[]" + dashes) event.current_buffer.cursor_left(len(dashes) + 1) - @kb.add("{", filter=focused_insert & preceding_text(r".*(r|R)[\"'](-*)$")) + @kb.add( + "{", filter=focused_insert & auto_match & preceding_text(r".*(r|R)[\"'](-*)$") + ) def _(event): matches = re.match( r".*(r|R)[\"'](-*)", @@ -180,12 +186,12 @@ def create_ipython_shortcuts(shell): event.current_buffer.insert_text("{}" + dashes) event.current_buffer.cursor_left(len(dashes) + 1) - @kb.add('"', filter=focused_insert & preceding_text(r".*(r|R)$")) + @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 & preceding_text(r".*(r|R)$")) + @kb.add("'", filter=focused_insert & auto_match & preceding_text(r".*(r|R)$")) def _(event): event.current_buffer.insert_text("''") event.current_buffer.cursor_left()