def _on_text_change(self, buffer: Buffer) -> None: """Disable replace mode and fix cursor position on text changes.""" self.buffer_replace = False if buffer.text and buffer.text != "-": self.value = self.value if buffer.text.startswith("-") and buffer.cursor_position == 0: buffer.cursor_position = 1
def dirWindow(path): text = ls(path) buffer = Buffer(document=Document(text), read_only=True) buffer.cursor_position = 0 # start at top of document bufferControl = BufferControl(buffer) win = Window(bufferControl, cursorline=True) add_bindings(buffer) return win
def _on_cursor_position_change(self, buffer: Buffer) -> None: """Fix cursor position on cursor movement.""" if self.focus_buffer.text.startswith( "-") and buffer.cursor_position == 0: buffer.cursor_position = 1