Skip to content

Commit 30c6e14

Browse files
committed
chore(json-crdt-peritext-ui): 🤖 remove unused code
1 parent 966c017 commit 30c6e14

File tree

2 files changed

+5
-41
lines changed

2 files changed

+5
-41
lines changed

src/json-crdt-peritext-ui/dom/CursorController.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ValueSyncStore} from '../../util/events/sync-store';
55
import type {Printable} from 'tree-dump';
66
import type {KeyController} from './KeyController';
77
import type {PeritextEventTarget} from '../events/PeritextEventTarget';
8-
import type {Rect, UiLifeCycles} from './types';
8+
import type {UiLifeCycles} from './types';
99
import type {Peritext} from '../../json-crdt-extensions/peritext';
1010
import type {Inline} from '../../json-crdt-extensions/peritext/block/Inline';
1111

@@ -55,46 +55,6 @@ export class CursorController implements UiLifeCycles, Printable {
5555
return -1;
5656
}
5757

58-
public caretRect(): Rect | undefined {
59-
const el = document.getElementById(this.caretId);
60-
if (!el) return;
61-
const rect = el.getBoundingClientRect();
62-
return rect;
63-
}
64-
65-
/**
66-
* Find text position at similar x coordinate on the next line.
67-
*
68-
* @param direction 1 for next line, -1 for previous line.
69-
* @returns The position at similar x coordinate on the next line, or
70-
* undefined if not found.
71-
*
72-
* @todo Implement similar functionality for finding soft line breaks (end
73-
* and start of lines). Or use `.getClientRects()` trick with `Range`
74-
* object, see: https://www.bennadel.com/blog/4310-detecting-rendered-line-breaks-in-a-text-node-in-javascript.htm
75-
*/
76-
public getNextLinePos(direction: 1 | -1 = 1): number | undefined {
77-
// TODO: this works only for the main cursor, make it work for all cursors.
78-
const rect = this.caretRect();
79-
if (!rect) return;
80-
const {x, y, width, height} = rect;
81-
const halfWidth = width / 2;
82-
const halfHeight = height / 2;
83-
const currentPos = this.opts.txt.editor.cursor.focus().viewPos();
84-
const caretPos = this.posAtPoint(x + halfWidth, y + halfHeight);
85-
if (currentPos !== caretPos) return;
86-
for (let i = 1; i < 16; i++) {
87-
const dy = i * direction * halfHeight;
88-
const pos = this.posAtPoint(x + halfWidth, y + dy);
89-
if (pos !== -1 && pos !== caretPos) {
90-
if (direction < 0) {
91-
if (pos < caretPos) return pos;
92-
} else if (pos > caretPos) return pos;
93-
}
94-
}
95-
return undefined;
96-
}
97-
9858
/** -------------------------------------------------- {@link UiLifeCycles} */
9959

10060
public start(): void {

src/json-crdt-peritext-ui/dom/DomController.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ export class DomController implements UiLifeCycles, Printable, PeritextUiApi {
107107
return rects[0];
108108
}
109109

110+
public caretRect(): Rect | undefined {
111+
return document.getElementById(this.cursor.caretId)?.getBoundingClientRect?.();
112+
}
113+
110114
/** ----------------------------------------------------- {@link Printable} */
111115

112116
public toString(tab?: string): string {

0 commit comments

Comments
 (0)