Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/desktop/src/renderer/components/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import {
isBareHttpUrl,
isInsideMarkdownLink,
wrapSelectionWithUrl,
continueMarkupKeymap,
editorLineKeymap,
} from '@dripnex/commands';
import {
createWikilinkHighlighter,
Expand Down Expand Up @@ -382,6 +384,7 @@ export const MarkdownEditor = forwardRef<MarkdownEditorHandle, MarkdownEditorPro

// Selection
drawSelection(),
EditorState.allowMultipleSelections.of(true),

// History (undo/redo)
history(),
Expand All @@ -400,8 +403,10 @@ export const MarkdownEditor = forwardRef<MarkdownEditorHandle, MarkdownEditorPro
search({ top: true }),
highlightSelectionMatches(),

// Keymaps
// Keymaps — Enter-continues-markup and F5/Ctrl-J before defaultKeymap
keymap.of([
continueMarkupKeymap,
...editorLineKeymap,
...defaultKeymap,
...searchKeymap,
...foldKeymap,
Expand All @@ -414,6 +419,9 @@ export const MarkdownEditor = forwardRef<MarkdownEditorHandle, MarkdownEditorPro
base: markdownLanguage,
codeLanguages: languages,
}),
markdownLanguage.data.of({
commentTokens: { block: { open: '<!--', close: '-->' } },
}),

// Syntax highlighting
syntaxHighlighting(markdownHighlighting),
Expand Down
72 changes: 71 additions & 1 deletion apps/desktop/src/renderer/hooks/useCommandRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,31 @@ import {
type KeyBinding,
} from '@dripnex/command-registry';
import { editorCommands } from '@dripnex/command-registry/definitions';
import { openSearchPanel, findNext, findPrevious } from '@codemirror/search';
import {
openSearchPanel,
findNext,
findPrevious,
selectNextOccurrence,
selectSelectionMatches,
} from '@codemirror/search';
import { toggleFold, foldAll, unfoldAll } from '@codemirror/language';
import {
copyLineUp,
copyLineDown,
moveLineUp,
moveLineDown,
insertBlankLine,
selectLine,
cursorMatchingBracket,
selectMatchingBracket,
selectParentSyntax,
cursorSubwordBackward,
cursorSubwordForward,
selectSubwordBackward,
selectSubwordForward,
toggleComment,
toggleLineComment,
} from '@codemirror/commands';
import {
toggleBold,
toggleItalic,
Expand All @@ -24,6 +47,21 @@ import {
insertHorizontalRule,
undoChange,
redoChange,
joinLines,
sortLines,
reverseSortLines,
sortLinesInsensitive,
reverseSortLinesInsensitive,
insertLineBefore,
upcaseAtCursor,
downcaseAtCursor,
findUnder,
findUnderPrevious,
skipAndSelectNextOccurrence,
splitSelectionByLine,
scrollLineUp,
scrollLineDown,
showInCenter,
} from '@dripnex/commands';
import { followWikilinkAtCursor } from '../utils/followWikilinkAtCursor';
import { acceptNes, dismissNes, triggerNes } from '../editor/nes/extension';
Expand Down Expand Up @@ -86,6 +124,38 @@ const editorExecutors: Record<string, (view: EditorView) => boolean | void> = {
'editor:trigger-nes': triggerNes,
'editor:accept-nes': acceptNes,
'editor:dismiss-nes': dismissNes,
'editor:copy-line-up': copyLineUp,
'editor:copy-line-down': copyLineDown,
'editor:move-line-up': moveLineUp,
'editor:move-line-down': moveLineDown,
'editor:insert-blank-line': insertBlankLine,
'editor:insert-line-before': insertLineBefore,
'editor:select-line': selectLine,
'editor:go-matching-bracket': cursorMatchingBracket,
'editor:select-matching-bracket': selectMatchingBracket,
'editor:select-parent-syntax': selectParentSyntax,
'editor:go-subword-left': cursorSubwordBackward,
'editor:go-subword-right': cursorSubwordForward,
'editor:select-subword-left': selectSubwordBackward,
'editor:select-subword-right': selectSubwordForward,
'editor:select-next-occurrence': selectNextOccurrence,
'editor:select-selection-matches': selectSelectionMatches,
'editor:toggle-comment': toggleComment,
'editor:toggle-line-comment': toggleLineComment,
'editor:sort-lines-insensitive': sortLinesInsensitive,
'editor:reverse-sort-lines-insensitive': reverseSortLinesInsensitive,
'editor:sort-lines': sortLines,
'editor:reverse-sort-lines': reverseSortLines,
'editor:join-lines': joinLines,
'editor:upcase-at-cursor': upcaseAtCursor,
'editor:downcase-at-cursor': downcaseAtCursor,
'editor:find-under': findUnder,
'editor:find-under-previous': findUnderPrevious,
'editor:skip-and-select-next-occurrence': skipAndSelectNextOccurrence,
'editor:split-selection-by-line': splitSelectionByLine,
'editor:scroll-line-up': scrollLineUp,
'editor:scroll-line-down': scrollLineDown,
'editor:show-in-center': showInCenter,
};

for (const def of editorCommands) {
Expand Down
233 changes: 233 additions & 0 deletions packages/command-registry/src/definitions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,237 @@ export const editorCommands: CommandDefinition[] = [
context: 'editor',
showInPalette: false,
},
{
id: 'editor:copy-line-up',
name: 'Copy Line Up',
category: 'editor',
context: 'editor',
defaultKeybinding: { key: 'arrowup', modifiers: ['Shift', 'Alt'] },
showInPalette: true,
},
{
id: 'editor:copy-line-down',
name: 'Copy Line Down',
category: 'editor',
context: 'editor',
defaultKeybinding: { key: 'arrowdown', modifiers: ['Shift', 'Alt'] },
showInPalette: true,
},
{
id: 'editor:move-line-up',
name: 'Move Line Up',
category: 'editor',
context: 'editor',
defaultKeybinding: { key: 'arrowup', modifiers: ['Alt'] },
showInPalette: true,
},
{
id: 'editor:move-line-down',
name: 'Move Line Down',
category: 'editor',
context: 'editor',
defaultKeybinding: { key: 'arrowdown', modifiers: ['Alt'] },
showInPalette: true,
},
{
id: 'editor:insert-blank-line',
name: 'Insert Blank Line Below',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:insert-line-before',
name: 'Insert Blank Line Above',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:select-line',
name: 'Select Line',
category: 'editor',
context: 'editor',
defaultKeybinding: { key: 'l', modifiers: ['Mod'] },
showInPalette: true,
},
{
id: 'editor:go-matching-bracket',
name: 'Go to Matching Bracket',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:select-matching-bracket',
name: 'Select Matching Bracket',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:select-parent-syntax',
name: 'Select Parent Syntax',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:go-subword-left',
name: 'Go Subword Left',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:go-subword-right',
name: 'Go Subword Right',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:select-subword-left',
name: 'Select Subword Left',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:select-subword-right',
name: 'Select Subword Right',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:select-next-occurrence',
name: 'Select Next Occurrence',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:select-selection-matches',
name: 'Select All Occurrences',
category: 'editor',
context: 'editor',
defaultKeybinding: { key: 'f3', modifiers: ['Alt'] },
showInPalette: true,
},
{
id: 'editor:toggle-comment',
name: 'Toggle Comment',
category: 'editor',
context: 'editor',
defaultKeybinding: { key: '/', modifiers: ['Mod'] },
showInPalette: true,
},
{
id: 'editor:toggle-line-comment',
name: 'Toggle Line Comment',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:sort-lines-insensitive',
name: 'Sort Lines',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:reverse-sort-lines-insensitive',
name: 'Sort Lines Reverse',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:sort-lines',
name: 'Sort Lines (Case Sensitive)',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:reverse-sort-lines',
name: 'Sort Lines Reverse (Case Sensitive)',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:join-lines',
name: 'Join Lines',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:upcase-at-cursor',
name: 'Uppercase',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:downcase-at-cursor',
name: 'Lowercase',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:find-under',
name: 'Find Under',
category: 'editor',
context: 'editor',
defaultKeybinding: { key: 'f3', modifiers: ['Mod'] },
showInPalette: true,
},
{
id: 'editor:find-under-previous',
name: 'Find Under Previous',
category: 'editor',
context: 'editor',
defaultKeybinding: { key: 'f3', modifiers: ['Mod', 'Shift'] },
showInPalette: true,
},
{
id: 'editor:skip-and-select-next-occurrence',
name: 'Skip and Select Next Occurrence',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:split-selection-by-line',
name: 'Split Selection by Line',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:scroll-line-up',
name: 'Scroll Line Up',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:scroll-line-down',
name: 'Scroll Line Down',
category: 'editor',
context: 'editor',
showInPalette: true,
},
{
id: 'editor:show-in-center',
name: 'Scroll Cursor to Center',
category: 'editor',
context: 'editor',
showInPalette: true,
},
];
20 changes: 20 additions & 0 deletions packages/commands/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ export {
} from './markdown/commands.js';
export type { GithubAlertKind } from './markdown/commands.js';

export { continueMarkup, continueMarkupKeymap } from './markdown/continueMarkup.js';
export {
joinLines,
sortLines,
reverseSortLines,
sortLinesInsensitive,
reverseSortLinesInsensitive,
insertLineBefore,
upcaseAtCursor,
downcaseAtCursor,
findUnder,
findUnderPrevious,
skipAndSelectNextOccurrence,
splitSelectionByLine,
scrollLineUp,
scrollLineDown,
showInCenter,
editorLineKeymap,
} from './markdown/lineCommands.js';

export {
SLASH_ITEMS,
FENCE_LANGUAGES,
Expand Down
Loading
Loading