Browse Source

remove unnecessary comments

WNomunomu 11 months ago
parent
commit
f7570eaac8
1 changed files with 7 additions and 9 deletions
  1. 7 9
      packages/editor/src/client/stores/use-editor-shortcuts.ts

+ 7 - 9
packages/editor/src/client/stores/use-editor-shortcuts.ts

@@ -53,10 +53,11 @@ const makeTextCodeBlock: Command = (view: EditorView) => {
     const selectedText = doc.sliceString(range.from, range.to, '');
     const selectedText = doc.sliceString(range.from, range.to, '');
     const isAlreadyWrapped = selectedText.startsWith('```') && selectedText.endsWith('```');
     const isAlreadyWrapped = selectedText.startsWith('```') && selectedText.endsWith('```');
 
 
+    const codeBlockMarkerLength = 4;
+
     if (isAlreadyWrapped) {
     if (isAlreadyWrapped) {
-      // Remove existing code block markers
-      const startMarkerEnd = startLine.from + 4; // '```\n' length
-      const endMarkerStart = endLine.to - 4; // '\n```' length
+      const startMarkerEnd = startLine.from + codeBlockMarkerLength;
+      const endMarkerStart = endLine.to - codeBlockMarkerLength;
 
 
       changes.push({
       changes.push({
         from: startLine.from,
         from: startLine.from,
@@ -70,8 +71,7 @@ const makeTextCodeBlock: Command = (view: EditorView) => {
         insert: '',
         insert: '',
       });
       });
 
 
-      // Position cursor at the start of the unwrapped content
-      newSelections.push(EditorSelection.range(startLine.from, endMarkerStart - 4));
+      newSelections.push(EditorSelection.range(startLine.from, endMarkerStart - codeBlockMarkerLength));
     }
     }
     else {
     else {
       // Add code block markers
       // Add code block markers
@@ -86,16 +86,14 @@ const makeTextCodeBlock: Command = (view: EditorView) => {
       });
       });
 
 
       if (selectedText.length === 0) {
       if (selectedText.length === 0) {
-        newSelections.push(EditorSelection.cursor(startLine.from + 4));
+        newSelections.push(EditorSelection.cursor(startLine.from + codeBlockMarkerLength));
       }
       }
       else {
       else {
-        // Position cursor to include the entire wrapped content with markers
-        newSelections.push(EditorSelection.range(startLine.from, endLine.to + 8));
+        newSelections.push(EditorSelection.range(startLine.from, endLine.to + codeBlockMarkerLength * 2));
       }
       }
     }
     }
   });
   });
 
 
-  // Send a single transaction with both changes and selection update
   view.dispatch({
   view.dispatch({
     changes,
     changes,
     selection: EditorSelection.create(newSelections),
     selection: EditorSelection.create(newSelections),