Skip to content

Commit e99d2ea

Browse files
chore(apollo-react): cleanup
1 parent 2013160 commit e99d2ea

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

packages/apollo-react/src/canvas/components/StickyNoteNode/StickyNoteNode.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { NodeToolbar } from '../Toolbar';
1212
import { FormattingToolbar } from './FormattingToolbar';
1313
import {
1414
type ActiveFormats,
15+
activeFormatsEqual,
1516
continueListOnEnter,
1617
detectActiveFormats,
1718
} from './markdown-formatting';
@@ -125,15 +126,13 @@ const StickyNoteNodeComponent = ({
125126
}, []);
126127

127128
const updateActiveFormats = useCallback(() => {
128-
if (textAreaRef.current) {
129-
setActiveFormats(
130-
detectActiveFormats({
131-
value: textAreaRef.current.value,
132-
selectionStart: textAreaRef.current.selectionStart,
133-
selectionEnd: textAreaRef.current.selectionEnd,
134-
})
135-
);
136-
}
129+
if (!textAreaRef.current) return;
130+
const next = detectActiveFormats({
131+
value: textAreaRef.current.value,
132+
selectionStart: textAreaRef.current.selectionStart,
133+
selectionEnd: textAreaRef.current.selectionEnd,
134+
});
135+
setActiveFormats((prev) => (activeFormatsEqual(prev, next) ? prev : next));
137136
}, []);
138137

139138
const shortcutKeyDown = useMarkdownShortcuts(textAreaRef, handleFormat);
@@ -348,7 +347,6 @@ const StickyNoteNodeComponent = ({
348347
onKeyDown={handleKeyDown}
349348
onSelect={updateActiveFormats}
350349
onKeyUp={updateActiveFormats}
351-
readOnly={!isEditing}
352350
placeholder={placeholder}
353351
isEditing={isEditing}
354352
className="nodrag nowheel"

packages/apollo-react/src/canvas/components/StickyNoteNode/markdown-formatting/detectActiveFormats.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ export type ActiveFormats = {
99
numberedList: boolean;
1010
};
1111

12+
export function activeFormatsEqual(a: ActiveFormats, b: ActiveFormats): boolean {
13+
return (
14+
a.bold === b.bold &&
15+
a.italic === b.italic &&
16+
a.strikethrough === b.strikethrough &&
17+
a.bulletList === b.bulletList &&
18+
a.numberedList === b.numberedList
19+
);
20+
}
21+
1222
export function detectActiveFormats(input: TextSelection): ActiveFormats {
1323
const { value, selectionStart } = input;
1424

@@ -17,8 +27,10 @@ export function detectActiveFormats(input: TextSelection): ActiveFormats {
1727
if (lineEnd === -1) lineEnd = value.length;
1828
const currentLine = value.slice(lineStart, lineEnd);
1929

20-
const textBefore = value.slice(0, selectionStart);
21-
const textAfter = value.slice(selectionStart);
30+
// Scope to current line only — inline markdown formatting never spans lines
31+
const cursorInLine = selectionStart - lineStart;
32+
const textBefore = currentLine.slice(0, cursorInLine);
33+
const textAfter = currentLine.slice(cursorInLine);
2234

2335
// Bold: find ** before/after cursor on same line, allowing single * (from italic) in between
2436
const bold =
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export { type ActiveFormats, detectActiveFormats } from './detectActiveFormats';
1+
export { type ActiveFormats, activeFormatsEqual, detectActiveFormats } from './detectActiveFormats';
22
export { toggleBold, toggleItalic, toggleStrikethrough } from './inlineFormatting';
33
export {
44
BULLET_PREFIX,
5+
continueListOnEnter,
56
NUMBERED_PREFIX,
67
NUMBERED_PREFIX_FULL,
7-
continueListOnEnter,
88
toggleBulletList,
99
toggleNumberedList,
1010
} from './listFormatting';

packages/apollo-react/src/canvas/components/StickyNoteNode/markdown-formatting/inlineFormatting.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TextSelection } from '../StickyNoteNode.types';
2-
import { BULLET_PREFIX, NUMBERED_PREFIX_FULL } from './listFormatting';
2+
import { BULLET_PREFIX, NUMBERED_PREFIX, NUMBERED_PREFIX_FULL } from './listFormatting';
33

44
/**
55
* Toggles an inline markdown wrapper (e.g., **, *, ~~) around the selected text.
@@ -88,7 +88,6 @@ function toggleInlineWrap(input: TextSelection, marker: string): TextSelection {
8888
}
8989

9090
const lines = value.slice(lineStart, lineEnd).split('\n');
91-
const NUMBERED_PREFIX = /^(\s*)\d+\.\s/;
9291

9392
if (
9493
lines.length >= 2 &&

0 commit comments

Comments
 (0)