Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add line numbers to code editors #5474

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/jaspJags
Submodule jaspJags updated 1 files
+1 −2 inst/qml/JAGS.qml
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
}
51 changes: 49 additions & 2 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,16 +87,62 @@ TextAreaBase
boundsBehavior: Flickable.StopAtBounds
anchors.fill: parent

Rectangle
{
id: lineNumbersRect
anchors.top: parent.top
anchors.left: parent.left
anchors.topMargin: jaspTheme.contentMargin
anchors.leftMargin: 2
visible: textArea.showLineNumber
width: lineNumbersRect.visible ? lineNumbers.width : 0
height: Math.max(flickableRectangle.height, control.contentHeight) + 10
color: "transparent"

FontMetrics
{
font: jaspTheme.fontCode
id: lineNumberWidthDeterminer
}

ListView
{
id: lineNumbers
width: lineNumberWidthDeterminer.advanceWidth(control.lineCount) + jaspTheme.itemPadding
height: parent.height
model: control.lineCount
delegate: Text
{
text: "<i>%1</i>".arg(index + 1)
font: jaspTheme.fontCode
color: jaspTheme.grayDarker
height: control.contentHeight / control.lineCount
anchors.right: parent.right
anchors.rightMargin: jaspTheme.itemPadding / 2
}
}

Rectangle
{
id: separator
anchors.top: parent.top
anchors.left: parent.right
width: 2 * preferencesModel.uiScale
height: Math.max(flickableRectangle.height, control.contentHeight) + 10
color: jaspTheme.borderColor
}
}

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

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

leftPadding: !textArea.showLineNumber ? 0 : lineNumbers.width + 2 * jaspTheme.contentMargin

Component.onCompleted:
{
if (textArea.nextTabItem)
Expand Down