-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix overlap between heading indicators and sidebar menu when sidebar is closed * Add placeholder text to editor when section content is empty * Bump version
- Loading branch information
1 parent
be43697
commit 7313ee9
Showing
6 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/renderer/components/codemirror/extensions/placeholder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Extension } from '@codemirror/state'; | ||
import { | ||
ViewPlugin, | ||
EditorView, | ||
Decoration, | ||
DecorationSet, | ||
WidgetType, | ||
} from '@codemirror/view'; | ||
|
||
class Placeholder extends WidgetType { | ||
constructor(readonly content: string | HTMLElement) { | ||
super(); | ||
} | ||
|
||
toDOM() { | ||
let wrap = document.createElement('span'); | ||
wrap.className = 'cm-placeholder'; | ||
wrap.style.pointerEvents = 'none'; | ||
wrap.appendChild( | ||
typeof this.content == 'string' | ||
? document.createTextNode(this.content) | ||
: this.content | ||
); | ||
if (typeof this.content == 'string') | ||
wrap.setAttribute('aria-label', 'placeholder ' + this.content); | ||
else wrap.setAttribute('aria-hidden', 'true'); | ||
return wrap; | ||
} | ||
|
||
ignoreEvent() { | ||
return false; | ||
} | ||
} | ||
|
||
/// Extension that enables a placeholder—a piece of example content | ||
/// to show when the editor is empty. | ||
const placeholder = (): Extension => { | ||
return ViewPlugin.fromClass( | ||
class { | ||
placeholder: DecorationSet; | ||
|
||
constructor(readonly view: EditorView) { | ||
const placeholderText = 'Start writing...'; | ||
|
||
this.placeholder = Decoration.set([ | ||
Decoration.widget({ | ||
widget: new Placeholder(placeholderText), | ||
side: 1, | ||
}).range(0), | ||
]); | ||
} | ||
|
||
update!: () => void; // Kludge to convince TypeScript that this is a plugin value | ||
|
||
get decorations() { | ||
return this.view.state.doc.length ? Decoration.none : this.placeholder; | ||
} | ||
}, | ||
{ decorations: (v) => v.decorations } | ||
); | ||
}; | ||
|
||
export default placeholder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters