Skip to content

Commit

Permalink
fix: move cursor up/down issus
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jan 9, 2024
1 parent c8ba248 commit 94c3d7e
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion lib/src/extensions/position_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,43 @@ extension PositionExtension on Position {
: rect.centerLeft.translate(0, rect.height);
}

return editorState.service.selectionService.getPositionInOffset(offset);
final position =
editorState.service.selectionService.getPositionInOffset(offset);

if (position != null && !position.path.equals(path)) {
return position;
}

if (upwards) {
final previous = selection.start.path.previous;
if (previous.isNotEmpty && !previous.equals(selection.start.path)) {
final node = editorState.document.nodeAtPath(previous);
final selectable = node?.selectable;
var offset = selection.startIndex;

Check warning on line 105 in lib/src/extensions/position_extension.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/extensions/position_extension.dart#L101-L105

Added lines #L101 - L105 were not covered by tests
if (selectable != null) {
offset = offset.clamp(
selectable.start().offset,
selectable.end().offset,

Check warning on line 109 in lib/src/extensions/position_extension.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/extensions/position_extension.dart#L107-L109

Added lines #L107 - L109 were not covered by tests
);
return Position(path: previous, offset: offset);

Check warning on line 111 in lib/src/extensions/position_extension.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/extensions/position_extension.dart#L111

Added line #L111 was not covered by tests
}
}
} else {
final next = selection.end.path.next;
if (next.isNotEmpty && !next.equals(selection.end.path)) {
final node = editorState.document.nodeAtPath(next);
final selectable = node?.selectable;

Check warning on line 118 in lib/src/extensions/position_extension.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/extensions/position_extension.dart#L118

Added line #L118 was not covered by tests
var offset = selection.endIndex;
if (selectable != null) {
offset = offset.clamp(
selectable.start().offset,
selectable.end().offset,

Check warning on line 123 in lib/src/extensions/position_extension.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/extensions/position_extension.dart#L121-L123

Added lines #L121 - L123 were not covered by tests
);
return Position(path: next, offset: offset);

Check warning on line 125 in lib/src/extensions/position_extension.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/extensions/position_extension.dart#L125

Added line #L125 was not covered by tests
}
}
}

return this;
}
}

0 comments on commit 94c3d7e

Please sign in to comment.