Skip to content

Commit

Permalink
feat: add line number view for code editor
Browse files Browse the repository at this point in the history
  • Loading branch information
shun2wang committed Apr 28, 2024
1 parent 31231bd commit b4b6ade
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions QMLComponents/components/JASP/Controls/JAGSTextArea.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import JASP 1.0
TextArea
{
textType: JASP.TextTypeJAGSmodel
showLineNumber: true
}
31 changes: 31 additions & 0 deletions QMLComponents/components/JASP/Controls/TextArea.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TextAreaBase
property var undoModel
property bool useTabAsSpaces : true
property var nextTabItem
property bool showLineNumber : false

Component.onCompleted: control.editingFinished.connect(editingFinished)

Expand Down Expand Up @@ -86,13 +87,43 @@ TextAreaBase
boundsBehavior: Flickable.StopAtBounds
anchors.fill: parent

Rectangle
{
id: lineNumbersRect
anchors.top: parent.top
anchors.left: parent.left
anchors.topMargin: 2
anchors.leftMargin: 1
visible: textArea.showLineNumber || textArea.textType !== JASP.TextTypeDefault || textArea.textType !== JASP.TextTypeSource
width: lineNumbersRect.visible ? lineNumbers.width : 0
width: textArea.showLineNumber ? lineNumbers.width * preferencesModel.uiScale : 0
height: Math.max(flickableRectangle.height, control.contentHeight)
color: jaspTheme.whiteBroken

ListView
{
id: lineNumbers
width: contentItem.childrenRect.width
height: parent.height
model: control.lineCount
delegate: Text {
text: index + 1 + "."
font: jaspTheme.fontCode
color: jaspTheme.grayDarker
anchors.right: parent.right
}
}
}

QTC.TextArea.flickable: QTC.TextArea
{
id: control
selectByMouse: true
selectedTextColor: jaspTheme.white
selectionColor: jaspTheme.itemSelectedColor

leftPadding: lineNumbersRect.width + 3

font: textArea.textType === JASP.TextTypeDefault || textArea.textType === JASP.TextTypeSource ? jaspTheme.font : jaspTheme.fontCode
color: textArea.enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled

Expand Down

0 comments on commit b4b6ade

Please sign in to comment.