Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
281ffd23
Unverified
Commit
281ffd23
authored
Apr 24, 2023
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: improve toggle selection under cursor in markdown editor
parent
51c40445
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
13 deletions
+23
-13
EditorMarkdown.vue
ux/src/components/EditorMarkdown.vue
+23
-13
No files found.
ux/src/components/EditorMarkdown.vue
View file @
281ffd23
...
...
@@ -428,9 +428,14 @@ async function toggleMarkup ({ start, end }) {
for
(
const
selection
of
editor
.
getSelections
())
{
const
selectedText
=
editor
.
getModel
().
getValueInRange
(
selection
)
if
(
!
selectedText
)
{
const
word
=
editor
.
getModel
().
getWordAtPosition
(
selection
.
getPosition
())
}
if
(
selectedText
.
startsWith
(
start
)
&&
selectedText
.
endsWith
(
end
))
{
const
wordObj
=
editor
.
getModel
().
getWordAtPosition
(
selection
.
getPosition
())
const
wordRange
=
new
Range
(
selection
.
startLineNumber
,
wordObj
.
startColumn
,
selection
.
endLineNumber
,
wordObj
.
endColumn
)
if
(
wordObj
.
word
.
startsWith
(
start
)
&&
wordObj
.
word
.
endsWith
(
end
))
{
edits
.
push
({
range
:
wordRange
,
text
:
wordObj
.
word
.
substring
(
start
.
length
,
wordObj
.
word
.
length
-
end
.
length
)
}
)
}
else
{
edits
.
push
({
range
:
wordRange
,
text
:
`${start
}
${wordObj.word
}
${end
}
`
}
)
}
}
else
if
(
selectedText
.
startsWith
(
start
)
&&
selectedText
.
endsWith
(
end
))
{
edits
.
push
({
range
:
selection
,
text
:
selectedText
.
substring
(
start
.
length
,
selectedText
.
length
-
end
.
length
)
}
)
}
else
{
edits
.
push
({
range
:
selection
,
text
:
`${start
}
${selectedText
}
${end
}
`
}
)
...
...
@@ -467,21 +472,26 @@ onMounted(async () => {
}
}
)
// Allow `*` in word pattern for quick styling (toggle bold/italic without selection)
// original https://github.com/microsoft/vscode/blob/3e5c7e2c570a729e664253baceaf443b69e82da6/extensions/markdown-basics/language-configuration.json#L55
monaco
.
languages
.
setLanguageConfiguration
(
'markdown'
,
{
wordPattern
:
/
([
*_
]
{1,2
}
|~~|`+
)?[\p
{Alphabetic
}
\p
{Number
}
\p
{Nonspacing_Mark
}
]
+
(
_+
[\p
{Alphabetic
}
\p
{Number
}
\p
{Nonspacing_Mark
}
]
+
)
*
\1
/g
u
}
)
// -> Initialize Monaco Editor
editor
=
monaco
.
editor
.
create
(
monacoRef
.
value
,
{
value
:
pageStore
.
content
,
language
:
'markdown'
,
theme
:
'wikijs'
,
automaticLayout
:
true
,
scrollBeyondLastLine
:
false
,
cursorBlinking
:
'blink'
,
cursorSmoothCaretAnimation
:
true
,
fontSize
:
16
,
formatOnType
:
true
,
language
:
'markdown'
,
lineNumbersMinChars
:
3
,
padding
:
{
top
:
10
,
bottom
:
10
}
,
scrollBeyondLastLine
:
false
,
tabSize
:
2
,
padding
:
{
top
:
10
,
bottom
:
10
}
,
theme
:
'wikijs'
,
value
:
pageStore
.
content
,
wordWrap
:
'on'
}
)
...
...
@@ -494,7 +504,7 @@ onMounted(async () => {
id
:
'markdown.extension.editing.toggleBold'
,
keybindings
:
[
monaco
.
KeyMod
.
CtrlCmd
|
monaco
.
KeyCode
.
KeyB
],
label
:
'Toggle bold'
,
precondition
:
'
editorHasSelection
'
,
precondition
:
''
,
run
(
ed
)
{
toggleMarkup
({
start
:
'**'
}
)
}
...
...
@@ -506,7 +516,7 @@ onMounted(async () => {
id
:
'markdown.extension.editing.toggleItalic'
,
keybindings
:
[
monaco
.
KeyMod
.
CtrlCmd
|
monaco
.
KeyCode
.
KeyI
],
label
:
'Toggle italic'
,
precondition
:
'
editorHasSelection
'
,
precondition
:
''
,
run
(
ed
)
{
toggleMarkup
({
start
:
'*'
}
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment