Edge case link widget fix
parent
6a047e1ef4
commit
a0670768e8
|
@ -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(
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue