From b70d88e7ee946ec1cc5b4df6b03680b00439a2e0 Mon Sep 17 00:00:00 2001 From: Antoine Lambert Date: Wed, 20 Nov 2024 16:07:37 +0100 Subject: [PATCH] talipot-python/PythonCodeEditor: Improve selection with Shift+Home When selecting backwards on a line when using Shift+Home, do not select indent patterns the first time the Home key is hit. --- library/talipot-python/src/PythonCodeEditor.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/talipot-python/src/PythonCodeEditor.cpp b/library/talipot-python/src/PythonCodeEditor.cpp index 8d46fe081e..e65376f691 100644 --- a/library/talipot-python/src/PythonCodeEditor.cpp +++ b/library/talipot-python/src/PythonCodeEditor.cpp @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2019-2023 The Talipot developers + * Copyright (C) 2019-2024 The Talipot developers * * Talipot is a fork of Tulip, created by David Auber * and the Tulip development Team from LaBRI, University of Bordeaux @@ -1060,6 +1060,15 @@ void PythonCodeEditor::keyPressEvent(QKeyEvent *e) { getCursorPosition(line, col); setSelection(line, col, line, col - _indentPattern.length()); removeSelectedText(); + } else if (e->key() == Qt::Key_Home && e->modifiers() == Qt::ShiftModifier) { + int line = 0, col = 0; + getCursorPosition(line, col); + int pos = textBeforeCursor.lastIndexOf(_indentPattern); + if (pos != -1 && (pos + _indentPattern.length()) < col) { + setSelection(line, pos + _indentPattern.length(), line, col); + } else { + QPlainTextEdit::keyPressEvent(e); + } } else { QPlainTextEdit::keyPressEvent(e);