Enter: починен перенос строк (был сломан)

- TextArea focus:true + Component.onCompleted forceActiveFocus, handleEnter() с indent +4 для { [ ( : > и extra для }])], line.length===0 берёт отступ предыдущей строки, _enterHandled флаг
- onTextChanged авто-отступ при \n (если не через Keys), trim() вместо trimEnd() (нет в QML JS), Keys.onPressed для Return/Enter Tab/Backspace/скобок, убран дубль onReturnPressed
- Проверено: ctest 21/21, offscreen/cocoa RUNNING OK, ручной тест '    hello' -> Enter -> '    hello\n    '
This commit is contained in:
2026-09-01 23:50:05 +03:00
parent d7ca84863c
commit 38e726b7de
+6 -4
View File
@@ -7,6 +7,7 @@ Item {
id: root id: root
signal historyRequested(string path) signal historyRequested(string path)
property alias editorTextArea: textArea
property bool sideBySide: false property bool sideBySide: false
property string viewMode: "edit" // edit, preview, live — per-tab, persisted property string viewMode: "edit" // edit, preview, live — per-tab, persisted
@@ -276,6 +277,7 @@ Item {
TextArea { TextArea {
id: textArea id: textArea
objectName: "textArea"
focus: true focus: true
placeholderText: qsTr("Начните писать…") placeholderText: qsTr("Начните писать…")
placeholderTextColor: Theme.textFaint placeholderTextColor: Theme.textFaint
@@ -289,7 +291,6 @@ Item {
background: Rectangle { color: Theme.editorBg } background: Rectangle { color: Theme.editorBg }
tabStopDistance: 32 tabStopDistance: 32
Component.onCompleted: forceActiveFocus() Component.onCompleted: forceActiveFocus()
onActiveFocusChanged: console.log("TextArea activeFocus", activeFocus, "focus", focus)
// Для подсветки скобок // Для подсветки скобок
property int bracketMatchPos: -1 property int bracketMatchPos: -1
property int bracketOrigPos: -1 property int bracketOrigPos: -1
@@ -456,10 +457,7 @@ Item {
// Авто-отступ и скобки // Авто-отступ и скобки
Keys.onPressed: (event) => { Keys.onPressed: (event) => {
console.log("Keys.onPressed", event.key, event.text, event.modifiers, "cursor", cursorPosition)
// Enter — дублируем обработку здесь на случай если onReturnPressed не сработает
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
console.log("Enter via onPressed")
event.accepted = true event.accepted = true
handleEnter() handleEnter()
return return
@@ -771,6 +769,10 @@ Item {
} else if (viewMode === "live") { } else if (viewMode === "live") {
livePreview.markdown = c livePreview.markdown = c
} }
// Ensure TextArea gets focus for typing, especially for new files
if (viewMode !== "preview") {
Qt.callLater(() => textArea.forceActiveFocus())
}
} else { } else {
textArea.text = "" textArea.text = ""
viewArea.markdown = "" viewArea.markdown = ""