From 4c7815554ce3e346a1a0f3b613b2c81cf1dc58f7 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 21 Jul 2019 19:12:32 -0400 Subject: [PATCH] Auto-indent new line in sendbox --- TODO.md | 3 +-- src/qml/Chat/SendBox.qml | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index e60b96d9..737e55c8 100644 --- a/TODO.md +++ b/TODO.md @@ -14,16 +14,15 @@ - When qml syntax highlighting supports string interpolation, use them - Fixes - - `
`, need to add width attribute - Keyboard flicking against top/bottom edge - Don't strip user spacing in html - Past events loading (limit 100) freezes the GUI - need to move upsert func to a WorkerScript - `MessageDelegate.qml:63: TypeError: 'reloadPreviousItem' not a function` - Horrible performance for big rooms + - [hr not working](https://bugreports.qt.io/browse/QTBUG-74342) - UI - - mod+enter in sendbox: respect previous line indent - When reduced, show the full-window sidepane instead of Default page - Adapt shortcuts flicking speed to font size and DPI - Show error box if uploading avatar fails diff --git a/src/qml/Chat/SendBox.qml b/src/qml/Chat/SendBox.qml index 6d1a33b7..db320561 100644 --- a/src/qml/Chat/SendBox.qml +++ b/src/qml/Chat/SendBox.qml @@ -8,6 +8,8 @@ import "../Base" HRectangle { function setFocus() { areaScrollView.forceActiveFocus() } + property string indent: " " + property var aliases: window.settings.writeAliases property string writingUserId: chatPage.userId property string toSend: "" @@ -40,6 +42,7 @@ HRectangle { id: areaScrollView placeholderText: qsTr("Type a message...") backgroundColor: "transparent" + area.tabStopDistance: 4 * 4 // 4 spaces area.focus: true function setTyping(typing) { @@ -109,7 +112,16 @@ HRectangle { event.modifiers & Qt.ControlModifier || event.modifiers & Qt.AltModifier) { - textArea.insert(textArea.cursorPosition, "\n") + let line = textArea.text.split("\n").slice(-1)[0] + let indents = 0 + + for (let part of line.split(indent)) { + if (part) { break } + indents += 1 + } + + let add = indent.repeat(indents) + textArea.insert(textArea.cursorPosition, "\n" + add) return } @@ -124,7 +136,7 @@ HRectangle { area.Keys.onEnterPressed.connect(area.Keys.onReturnPressed) area.Keys.onTabPressed.connect(event => { - textArea.insert(textArea.cursorPosition, " ") + textArea.insert(textArea.cursorPosition, indent) }) } }