Add some checks before reading file.

This commit is contained in:
2025-03-31 19:26:04 -04:00
parent b426b88b79
commit 365940267f
3 changed files with 36 additions and 21 deletions

View File

@@ -35,31 +35,36 @@ SplitView {
// extend the available height.
Flickable {
id: lineNumbers
Layout.fillHeight: true
Layout.fillWidth: false
// Calculate the width based on the logarithmic scale.
// Calculating the width correctly is important as the number grows.
// We need to ensure space required to show N line number digits.
// We use log10 to find how many digits are needed in a line number.
// log10(9) ~= .95; log10(10) = 1.0; log10(100) = 2.0 ...etc
// We +1 to ensure space for at least 1 digit, as floor(1.95) = 1.
// The +10 is additional spacing and can be adjusted.
Layout.preferredWidth: fontMetrics.averageCharacterWidth * (Math.floor(Math.log10(textArea.lineCount)) + 1) + 10
contentY: editorFlickable.contentY
interactive: false
visible: true
Column {
anchors.fill: parent
topPadding: 6
topPadding: textArea.topPadding
Repeater {
id: repeatedLineNumbers
// TODO: Bug where text wrapping shows as new line number.
model: textArea.lineCount
// Each line number in the gutter.
// This Item is used for each line number in the gutter.
delegate: Item {
required property int index
// Calculate the height of each line in the text area.
// Calculates the height of each line in the text area.
height: textArea.contentHeight / textArea.lineCount
width: parent.width
required property int index
// Show the line number.
Label {
id: numbers
@@ -69,8 +74,9 @@ SplitView {
horizontalAlignment: Text.AlignLeft
text: parent.index + 1
verticalAlignment: Text.AlignVCenter
width: parent.width
width: parent.width - indicator.width
}
// Draw edge along the right side of the line number.
Rectangle {
id: indicator
@@ -80,14 +86,11 @@ SplitView {
width: 1
}
}
// TODO: Bug where text wrapping shows as new line number.
model: textArea.lineCount
}
}
}
Flickable {
id: editorFlickable
Layout.fillHeight: true
Layout.fillWidth: true
boundsBehavior: Flickable.StopAtBounds
@@ -97,6 +100,7 @@ SplitView {
}
ScrollBar.vertical: MyScrollBar {
}
TextArea.flickable: TextArea {
id: textArea
@@ -104,8 +108,8 @@ SplitView {
focus: true
persistentSelection: true
selectByMouse: true
// selectedTextColor: RustColors.editor_highlighted_text
// selectionColor: RustColors.editor_highlight
selectedTextColor: RustColors.editor_highlighted_text
selectionColor: RustColors.editor_highlight
textFormat: Qt.AutoText
wrapMode: TextArea.Wrap
text: FileSystem.readFile(root.filePath)