Skip to content

Commit

Permalink
Modify caret move
Browse files Browse the repository at this point in the history
  • Loading branch information
naotsugu committed Feb 1, 2024
1 parent b2a1aa4 commit 7a20468
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public interface Caret {
*/
void down();

/**
* Move the caret to the home.
*/
void home();

/**
* Move the caret to the end.
*/
void end();

/**
* Get the point at caret.
* Return {@code null} if caret is off-screen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ public void down() {
y = next.offsetY();
}

@Override
public void home() {

}

@Override
public void end() {

}


@Override
public OffsetPoint caretPoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ public void down() {
moons.forEach(CaretLine::down);
}

@Override
public void home() {
main.home();
moons.forEach(CaretLine::home);
}

@Override
public void end() {
main.end();
moons.forEach(CaretLine::end);
}

@Override
public OffsetPoint caretPoint() {
if (offset() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ public void down() {
}


public void home() {
boolean skipWhitespace = true;
if (line.offset() != bar.offset()) {
if (bar.offset() - line.offset() < 36 &&
line.text().substring(0, (int) (bar.offset() - line.offset())).trim().isEmpty()) {
skipWhitespace = false;
}
at(line.offset());
}
if (skipWhitespace) {
if (Character.isWhitespace(line.charAt(bar.offset()))) {
while (bar.offset() < line.tailOffset() &&
Character.isWhitespace(line.charAt(bar.offset()))) {
right();
}
}
}
}


public void end() {
at(line.tailOffset() - line.endMarkCount());
}


public void refresh() {
long offset = bar.offset();
line = offsetToLine.apply(offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,31 +499,13 @@ public void moveCaretDown() {
@Override
public void moveCaretLineHome() {
vScrollToCaret();
LayoutLine line = texts.layoutLine(caret.offset());
boolean skipWhitespace = true;
if (line.offset() != caret.offset()) {
if (caret.offset() - line.offset() < 36 &&
line.text().substring(0, (int) (caret.offset() - line.offset())).trim().isEmpty()) {
skipWhitespace = false;
}
caret.at(line.offset(), true);
}
if (skipWhitespace) {
if (Character.isWhitespace(line.charAt(caret.offset()))) {
while (caret.offset() < line.tailOffset() &&
Character.isWhitespace(line.charAt(caret.offset()))) {
caret.right();
}
}
}
caret.home();
screen.hScrollTo(caret.x());
}
@Override
public void moveCaretLineEnd() {
vScrollToCaret();
LayoutLine line = texts.layoutLine(caret.offset());
long offset = line.tailOffset() - line.endMarkCount();
caret.at(offset, true);
caret.end();
screen.hScrollTo(caret.x());
}
// </editor-fold>
Expand Down

0 comments on commit 7a20468

Please sign in to comment.