blob: 052933da20fa57cd8598184b76df8d48bac0e737 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
pragma ComponentBehavior: Bound
import QtQuick 6.7
import QtQuick.Controls 6.7 as QQC2
import QtQuick.Layouts 6.7
import org.kde.kirigami as Kirigami
import org.kde.syntaxhighlighting
import org.deprecated.kodereviewer
TextEdit {
id: root
required property string file
signal commentClicked(string path, int startLine, int endLine)
signal newComment(string path, int startLine, int endLine)
property string filename: "A.patch"
property int lineHeight: contentHeight / lineCount
leftPadding: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing * 2
readOnly: true
textFormat: TextEdit.PlainText
wrapMode: TextEdit.Wrap
color: Kirigami.Theme.textColor
selectionColor: Kirigami.Theme.highlightColor
font.family: "monospace"
Kirigami.SpellCheck.enabled: false
LineModel {
id: lineModel
document: root.textDocument
onDocumentChanged: print('Document changed!')
}
onWidthChanged: lineModel.resetModel()
onHeightChanged: lineModel.resetModel()
SyntaxHighlighter {
id: highlighter
textEdit: root
definition: Repository.definitionForFileName(root.filename)
}
Kirigami.Separator {
anchors {
top: root.top
bottom: root.bottom
left: lineNumberColumn.right
leftMargin: Kirigami.Units.smallSpacing
}
}
ColumnLayout {
id: lineNumberColumn
anchors {
top: root.top
topMargin: root.topPadding
left: root.left
leftMargin: Kirigami.Units.smallSpacing
}
spacing: 0
Repeater {
id: repeater
model: lineModel
delegate: QQC2.Label {
id: label
required property int index
required property int lineHeight
Layout.fillWidth: true
Layout.preferredHeight: lineHeight
horizontalAlignment: Text.AlignRight
text: index + 1
color: Kirigami.Theme.disabledTextColor
font.family: "monospace"
}
}
}
// onTextChanged: lineModel.document = root.textDocument
onFileChanged: {
repeater.model.resetModel()
}
function selectionStartLine() {
const beforeText = text.toString().substr(0, selectionStart)
return beforeText.split("\n").length
}
function selectionEndLine() {
const beforeText = text.toString().substr(0, selectionEnd)
return beforeText.split("\n").length
}
}
|