Skip to content

Commit 3e2025c

Browse files
committed
Fix iOS h1~h4 bug (misfunction on last line & single line)
1 parent 1d5f0eb commit 3e2025c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/components/write/WriteMarkdownEditor.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ export default class WriteMarkdownEditor extends React.Component<
353353
const lastNewLineIndex = sliced.lastIndexOf('\n');
354354
const textBefore = sliced.slice(0, lastNewLineIndex + 1);
355355
const textAfter = markdown.slice(lastNewLineIndex + 1, markdown.length);
356-
const currentNewLineIndex = textAfter.indexOf('\n');
356+
let currentNewLineIndex = textAfter.indexOf('\n');
357+
if (currentNewLineIndex === -1) currentNewLineIndex = textAfter.length;
358+
357359
const lineText = textAfter.slice(0, currentNewLineIndex);
358360
const textBelowCurrentLine = textAfter.slice(
359361
currentNewLineIndex,
@@ -366,6 +368,8 @@ export default class WriteMarkdownEditor extends React.Component<
366368
this.appleEditorElement.current!.selectionEnd = pos;
367369
}, 0);
368370
};
371+
372+
console.log({ lineText });
369373
const handlers: {
370374
[key: string]: () => void;
371375
} = {

0 commit comments

Comments
 (0)