Skip to content

Commit

Permalink
chore: rename word from caret to cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
luolonghao committed Dec 24, 2024
1 parent ca51f23 commit f784646
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,19 +550,19 @@ export class Editor {
this.container.blur();
}

// Scrolls to the caret or the range of the selection.
// Scrolls to the cursor or the range of the selection.
public scrollToCaret(): void {
const range = this.selection.range;
if (range.isBox) {
return;
}
// Creates an artificial caret that is the same size as the caret at the current caret position.
// Creates an artificial cursor that is the same size as the cursor at the current cursor position.
const rangeRect = range.getRect();
if (rangeRect.x === 0 || rangeRect.y === 0) {
return;
}
const containerRect = (this.container.get(0) as Element).getBoundingClientRect();
const artificialCaret = query('<div class="lake-artificial-caret" />');
const artificialCaret = query('<div class="lake-artificial-cursor" />');
const left = rangeRect.x - containerRect.x;
const top = rangeRect.y - containerRect.y;
artificialCaret.css({
Expand All @@ -574,7 +574,7 @@ export class Editor {
// background: 'red',
'z-index': '-1',
});
this.overlayContainer.find('.lake-artificial-caret').remove();
this.overlayContainer.find('.lake-artificial-cursor').remove();
this.overlayContainer.append(artificialCaret);
scrollToNode(artificialCaret, {
behavior: 'instant',
Expand Down
2 changes: 1 addition & 1 deletion src/managers/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function appendNextNestedNodes(activeItems: ActiveItem[], range: Range): void {
}

export class Selection {
// Represents the range of text selected by the user or the current position of the caret.
// Represents the range of text selected by the user or the current position of the cursor.
private selection: NativeSelection;

// Is the root element which has contenteditable="true" attribute.
Expand Down
4 changes: 2 additions & 2 deletions src/models/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ export class Range {

// Relocates the start and end points of the range for <br /> element.
// In composition mode (e.g., when a user starts entering a Chinese character using a Pinyin IME),
// uncompleted text is inserted if the caret is positioned behind a <br> tag.
// To fix this bug, the caret needs to be moved to the front of the <br> tag.
// uncompleted text is inserted if the cursor is positioned behind a <br> tag.
// To fix this bug, the cursor needs to be moved to the front of the <br> tag.
public adjustBr(): void {
if (!this.isCollapsed) {
return;
Expand Down
6 changes: 3 additions & 3 deletions tests/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ describe('editor', () => {
expect(currentValue).to.equal(output);
});

it('fixContent method: should fix caret', () => {
it('fixContent method: should fix cursor', () => {
const input = '<p><br /><focus /></p>';
const output = '<p><focus /><br /></p>';
const editor = new Editor({
Expand Down Expand Up @@ -459,8 +459,8 @@ describe('editor', () => {
editor.selection.range.collapseToStart();
editor.scrollToCaret();
expect(nativeRootNode.scrollTop).to.equal(0);
// should remove fake caret
expect(editor.overlayContainer.find('.lake-artificial-caret').length).to.equal(0);
// should remove fake cursor
expect(editor.overlayContainer.find('.lake-artificial-cursor').length).to.equal(0);
editor.unmount();
});

Expand Down

0 comments on commit f784646

Please sign in to comment.