import QtQuick import QtQuick.Controls import QtQuick.Layouts Item { id: pane property int docIndex: -1 property bool editMode: true property bool canOpenBeside: false property bool closable: false signal openBeside() signal closePane() function insertText(t) { editor.insert(editor.cursorPosition, t) } // Шапка файла — плавающий оверлей Rectangle { anchors.top: parent.top anchors.left: parent.left anchors.right: parent.right height: 30 z: 10 color: "#f0f0f0" border.color: "#ddd" RowLayout { anchors.fill: parent anchors.leftMargin: 8 anchors.rightMargin: 4 spacing: 6 Label { Layout.fillWidth: true elide: Text.ElideMiddle color: "#444" text: documentManager.titleAt(pane.docIndex) } ToolButton { text: "✎" checkable: true checked: pane.editMode onClicked: pane.editMode = true } ToolButton { text: "👁" checkable: true checked: !pane.editMode onClicked: pane.editMode = false } ToolButton { text: "\u2715" visible: pane.closable onClicked: pane.closePane() } } } // TextArea — заполняет ВСЁ пространство TextArea { id: editor anchors.fill: parent visible: pane.editMode color: "black" font.family: "monospace" font.pixelSize: 14 padding: 10 onTextEdited: documentManager.updateContent(pane.docIndex, text) } // Просмотр TextArea { id: viewer anchors.fill: parent visible: !pane.editMode readOnly: true color: "black" font.family: "monospace" font.pixelSize: 14 padding: 10 onLinkActivated: (href) => { if (href.startsWith("flora://task/")) { const line = Number(href.substring(14)) if (line > 0) { const lines = editor.text.split("\n") const ln = lines[line - 1] if (ln !== undefined) { if (/\[ \]/.test(ln)) lines[line - 1] = ln.replace("[ ]", "[x]") else if (/\[x\]/.test(ln)) lines[line - 1] = ln.replace("[x]", "[ ]") editor.text = lines.join("\n") documentManager.updateContent(pane.docIndex, editor.text) } } } else if (href.startsWith("flora://open/")) { documentManager.openDocument(decodeURIComponent(href.substring(13))) } } } // Загрузка контента при смене файла function refresh() { const idx = pane.docIndex if (idx >= 0) { const c = documentManager.contentAt(idx) editor.text = c viewer.text = mdParser.render(c, fileStore.vault, filePathDir(documentManager.pathAt(idx))) } else { editor.text = "" viewer.text = "" } } function filePathDir(p) { const i = p.lastIndexOf("/") return i >= 0 ? p.substring(0, i) : p } onDocIndexChanged: refresh() onEditModeChanged: { if (!editMode) refresh() } Connections { target: documentManager function onActiveIndexChanged() { if (documentManager.activeIndex === pane.docIndex) refresh() } } Component.onCompleted: refresh() }