Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP1stack specificStack: typescript
editorprosemirrorselectioncorrectness
Replace the active selection range when inserting editor content
Insert pasted/generated nodes over the current selection range rather than ignoring it, so existing selected content is not orphaned or duplicated.
PR: hegnar-components · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const node = schema.nodeFromJSON(tableNode); |
| 2 | tr.insert(from, node); // ignores selection 'to', leaves stale selected text |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const { from, to } = view.state.selection; |
| 2 | const node = schema.nodeFromJSON(tableNode); |
| 3 | tr.replaceWith(from, to, node); // replaces the whole selection |
Explanation (EN)
Objašnjenje (HR)