Skip to content

Commit

Permalink
fix(line numbers): argument 'text' might be null
Browse files Browse the repository at this point in the history
  • Loading branch information
Li Guanglin committed Aug 24, 2023
1 parent 26f33c1 commit a7cf4fb
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ static class LineNumbersDrawer {
private float _oldTextSize;
private final int[] _startLine = {0, 1}; // {line index, actual line number}

private final GsTextWatcherAdapter lineTrackingWatcher = new GsTextWatcherAdapter() {
private final GsTextWatcherAdapter _lineTrackingWatcher = new GsTextWatcherAdapter() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
_maxNumber -= TextViewUtils.countChar(s, start, start + count, '\n');
Expand Down Expand Up @@ -541,14 +541,17 @@ public boolean isOutOfLineNumbersArea() {
}

public void startLineTracking() {
_editor.removeTextChangedListener(_lineTrackingWatcher);
_maxNumber = 1;
final CharSequence text = _editor.getText();
_maxNumber = TextViewUtils.countChar(text, 0, text.length(), '\n') + 1;
_editor.removeTextChangedListener(lineTrackingWatcher);
_editor.addTextChangedListener(lineTrackingWatcher);
if (text != null) {
_maxNumber += TextViewUtils.countChar(text, 0, text.length(), '\n');
}
_editor.addTextChangedListener(_lineTrackingWatcher);
}

public void stopLineTracking() {
_editor.removeTextChangedListener(lineTrackingWatcher);
_editor.removeTextChangedListener(_lineTrackingWatcher);
}

/**
Expand Down

0 comments on commit a7cf4fb

Please sign in to comment.