MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / renderCellCursor

Method renderCellCursor

packages/app-core/src/lib/cm-table.ts:906–939  ·  view source on GitHub ↗

Draw the block cursor over the character at `cursorOffset`, measuring its * rect from the cell's text node (so it tracks real glyph positions).

(cell: HTMLElement)

Source from the content-addressed store, hash-verified

904 /** Draw the block cursor over the character at `cursorOffset`, measuring its
905 * rect from the cell's text node (so it tracks real glyph positions). */
906 private renderCellCursor(cell: HTMLElement): void {
907 this.clearCellCursor(cell)
908 const text = cell.dataset.raw ?? ''
909 const offset = Math.max(0, Math.min(this.cursorOffset, Math.max(0, text.length - 1)))
910 this.cursorOffset = offset
911 const cursor = document.createElement('span')
912 cursor.className = 'cm-table-cell-cursor'
913 cursor.setAttribute('contenteditable', 'false')
914 const node = cell.firstChild
915 const cellRect = cell.getBoundingClientRect()
916 const range = document.createRange()
917 if (
918 node &&
919 node.nodeType === Node.TEXT_NODE &&
920 text.length > 0 &&
921 typeof range.getBoundingClientRect === 'function'
922 ) {
923 range.setStart(node, offset)
924 range.setEnd(node, Math.min(text.length, offset + 1))
925 const rect = range.getBoundingClientRect()
926 cursor.style.left = `${rect.left - cellRect.left}px`
927 cursor.style.top = `${rect.top - cellRect.top}px`
928 cursor.style.width = `${Math.max(rect.width, 3)}px`
929 cursor.style.height = `${rect.height || 18}px`
930 } else {
931 // Empty cell, or no measurement available (e.g. jsdom): a thin block at
932 // the cell's start.
933 cursor.style.left = '10px'
934 cursor.style.top = '5px'
935 cursor.style.bottom = '5px'
936 cursor.style.width = '0.5em'
937 }
938 cell.appendChild(cursor)
939 }
940
941 /** Vim NORMAL `l`: next character; at the cell's end, jump to the next
942 * column. */

Callers 6

onCellKeydownMethod · 0.95
enterNormalCellMethod · 0.95
moveCharRightMethod · 0.95
moveCharLeftMethod · 0.95
deleteRangeMethod · 0.95
handleVisualKeyMethod · 0.95

Calls 1

clearCellCursorMethod · 0.95

Tested by

no test coverage detected