From 88eee5194187c9575f5af49bd749d3e9950f727d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E8=BD=B2?= Date: Sun, 17 Sep 2023 20:50:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=A1=8C=E5=8F=B7=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=9B=B4=E6=96=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/bottom/status/BottomStatusBox.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/org/jcnc/jnotepad/views/root/center/main/bottom/status/BottomStatusBox.java b/src/main/java/org/jcnc/jnotepad/views/root/center/main/bottom/status/BottomStatusBox.java index 4a064dc..4cf2baa 100644 --- a/src/main/java/org/jcnc/jnotepad/views/root/center/main/bottom/status/BottomStatusBox.java +++ b/src/main/java/org/jcnc/jnotepad/views/root/center/main/bottom/status/BottomStatusBox.java @@ -1,5 +1,7 @@ package org.jcnc.jnotepad.views.root.center.main.bottom.status; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.Label; @@ -114,10 +116,31 @@ public class BottomStatusBox extends AbstractHorizontalBox { CenterTab centerTab = instance.getSelected(); if (centerTab != null) { updateEncodingLabel(centerTab.getCharset().name()); + + // 添加光标位置变化监听器 + LineNumberTextArea textArea = centerTab.getLineNumberTextArea(); + textArea.caretPositionProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Number oldValue, Number newValue) { + updateRowColumnLabel(textArea.getCaretPosition(), textArea.getText()); + } + }); } } } + /** + * 更新行列信息 + * @param caretPosition 光标位置 + * @param text 文本内容 + */ + private void updateRowColumnLabel(int caretPosition, String text) { + int row = getRow(caretPosition, text); + int column = getColumn(caretPosition, text); + statusLabel.setText(getStatusBarFormattedText(row, column, text.length())); + } + + /** * 获取光标所在行号。 *