[accerciser: 1/2] ipython_view: Clear output on Ctrl+L




commit 59192270fa0655a0660d50d201eb157789ed3061
Author: Michael Weghorn <m weghorn posteo de>
Date:   Thu Oct 28 08:09:49 2021 +0200

    ipython_view: Clear output on Ctrl+L
    
    This adds the functionality to clear the old
    output from the iypthon_view when pressing
    Ctrl+L (with either lower- or upper-case 'L'),
    just as is possible on a standalone interactive
    IPython shell.
    
    If anything was typed in the current input line,
    that text and the cursor position are remembered
    and restored.

 plugins/ipython_view.py | 9 +++++++++
 1 file changed, 9 insertions(+)
---
diff --git a/plugins/ipython_view.py b/plugins/ipython_view.py
index e03b70f..ff9ed09 100755
--- a/plugins/ipython_view.py
+++ b/plugins/ipython_view.py
@@ -552,6 +552,15 @@ class ConsoleView(gtk.TextView):
       insert_iter.backward_cursor_position()
       if not insert_iter.editable(True):
         return True
+    elif event.state & gdk.ModifierType.CONTROL_MASK and event.keyval in [ord('L'), ord('l')]:
+        # clear previous output on Ctrl+L, but remember current input line + cursor position
+        cursor_offset = self.text_buffer.get_property('cursor-position')
+        cursor_pos_in_line = cursor_offset - start_iter.get_offset() + len(self.prompt)
+        current_input = self.text_buffer.get_text(start_iter, self.text_buffer.get_end_iter(), False)
+        self.text_buffer.set_text(self.prompt + current_input)
+        self.text_buffer.move_mark(self.line_start, self.text_buffer.get_iter_at_offset(len(self.prompt)))
+        self.text_buffer.place_cursor(self.text_buffer.get_iter_at_offset(cursor_pos_in_line))
+        return True
     elif not event.string:
       pass
     elif start_iter.compare(insert_iter) <= 0 and \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]