Edge case link widget fix

pull/138/head
Zef Hemel 2022-11-29 09:17:40 +01:00
parent 6a047e1ef4
commit a0670768e8
2 changed files with 13 additions and 8 deletions

View File

@ -34,6 +34,17 @@ export function linkPlugin(editor: Editor) {
if (isCursorInRange(view.state, [from, to])) { if (isCursorInRange(view.state, [from, to])) {
return; return;
} }
const text = view.state.sliceDoc(from, to);
// Links are of the form [hell](https://example.com)
const [anchorPart, linkPart] = text.split("]("); // Not pretty
if (!linkPart) {
// Invalid link
return;
}
const cleanAnchor = anchorPart.substring(1); // cut off the initial [
const cleanLink = linkPart.substring(0, linkPart.length - 1); // cut off the final )
// Hide the whole thing // Hide the whole thing
widgets.push( widgets.push(
invisibleDecoration.range( invisibleDecoration.range(
@ -42,12 +53,6 @@ export function linkPlugin(editor: Editor) {
), ),
); );
const text = view.state.sliceDoc(from, to);
// Links are of the form [hell](https://example.com)
const [anchorPart, linkPart] = text.split("]("); // Not pretty
const cleanAnchor = anchorPart.substring(1); // cut off the initial [
const cleanLink = linkPart.substring(0, linkPart.length - 1); // cut off the final )
widgets.push( widgets.push(
Decoration.widget({ Decoration.widget({
widget: new LinkWidget( widget: new LinkWidget(

View File

@ -304,8 +304,8 @@ export class Editor {
let initialCursorPos = 0; let initialCursorPos = 0;
const match = frontMatterRegex.exec(pageText); const match = frontMatterRegex.exec(pageText);
if (match) { if (match) {
// Frotnmatter found, put cursor after it // Frontmatter found, put cursor after it
initialCursorPos = match[0].length; initialCursorPos = match[0].length + 1;
} }
// By default scroll to the top // By default scroll to the top
this.editorView.scrollDOM.scrollTop = 0; this.editorView.scrollDOM.scrollTop = 0;