Edge case link widget fix
parent
6a047e1ef4
commit
a0670768e8
|
@ -34,6 +34,17 @@ export function linkPlugin(editor: Editor) {
|
|||
if (isCursorInRange(view.state, [from, to])) {
|
||||
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
|
||||
widgets.push(
|
||||
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(
|
||||
Decoration.widget({
|
||||
widget: new LinkWidget(
|
||||
|
|
|
@ -304,8 +304,8 @@ export class Editor {
|
|||
let initialCursorPos = 0;
|
||||
const match = frontMatterRegex.exec(pageText);
|
||||
if (match) {
|
||||
// Frotnmatter found, put cursor after it
|
||||
initialCursorPos = match[0].length;
|
||||
// Frontmatter found, put cursor after it
|
||||
initialCursorPos = match[0].length + 1;
|
||||
}
|
||||
// By default scroll to the top
|
||||
this.editorView.scrollDOM.scrollTop = 0;
|
||||
|
|
Loading…
Reference in New Issue