Skip to content

Commit 415ad73

Browse files
committed
Update template mode styles
1 parent a4b38f1 commit 415ad73

File tree

7 files changed

+158
-177
lines changed

7 files changed

+158
-177
lines changed

workspaces/ballerina/ballerina-side-panel/src/components/editors/ExpandedEditor/controls/CodeMirrorMarkdownToolbar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
insertMarkdownUnorderedList,
2929
insertMarkdownOrderedList,
3030
insertMarkdownTaskList
31-
} from "../utils/codemirrorMarkdownUtils";
31+
} from "../utils/templateUtils";
3232
import { HelperPaneToggleButton } from "../../../editors/MultiModeExpressionEditor/ChipExpressionEditor/components/HelperPaneToggleButton";
3333

3434
const ToolbarContainer = styled.div`
@@ -138,6 +138,7 @@ export const CodeMirrorMarkdownToolbar = React.forwardRef<HTMLDivElement, CodeMi
138138
{helperPaneToggle && (
139139
<HelperPaneToggleButton
140140
ref={helperPaneToggle.ref}
141+
disabled={isPreviewMode}
141142
isOpen={helperPaneToggle.isOpen}
142143
onClick={helperPaneToggle.onClick}
143144
sx={{ marginBottom: 0 }}

workspaces/ballerina/ballerina-side-panel/src/components/editors/ExpandedEditor/controls/MarkdownPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import rehypeRaw from "rehype-raw";
2424
import remarkGfm from "remark-gfm";
2525
import { ChipComponent } from "./ChipComponent";
2626
import { DocumentType } from "../../MultiModeExpressionEditor/ChipExpressionEditor/types";
27-
import "../utils/markdown-preview.css";
27+
import "../styles/markdown-preview.css";
2828

2929
const PreviewContainer = styled.div`
3030
width: 100%;

workspaces/ballerina/ballerina-side-panel/src/components/editors/ExpandedEditor/utils/codemirrorListContinuation.ts

Lines changed: 0 additions & 171 deletions
This file was deleted.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
import { EditorView } from "@codemirror/view";
20+
import { KeyBinding } from "@codemirror/view";
2021

2122
/**
2223
* Inserts or removes markdown formatting around selected text (toggles)
@@ -445,3 +446,145 @@ export const insertMarkdownTaskList = (view: EditorView | null) => {
445446

446447
view.focus();
447448
};
449+
450+
export const handleEnterForListContinuation = (view: EditorView): boolean => {
451+
const state = view.state;
452+
const selection = state.selection.main;
453+
454+
// Only handle if there's no selection (just a cursor)
455+
if (selection.from !== selection.to) {
456+
return false;
457+
}
458+
459+
const cursorPosition = selection.from;
460+
const line = state.doc.lineAt(cursorPosition);
461+
const lineText = line.text;
462+
463+
// Check if cursor is at the end of the line or in the middle
464+
const cursorInLine = cursorPosition - line.from;
465+
466+
// Check for task list (- [ ] or - [x])
467+
const taskMatch = lineText.match(/^(\s*)([-*])\s+\[([ x])\]\s+(.*)$/);
468+
if (taskMatch) {
469+
const [, indent, marker, , content] = taskMatch;
470+
471+
// If the task item is empty, remove it and exit list mode
472+
if (!content.trim()) {
473+
view.dispatch({
474+
changes: {
475+
from: line.from,
476+
to: line.to,
477+
insert: ''
478+
},
479+
selection: {
480+
anchor: line.from
481+
}
482+
});
483+
return true;
484+
}
485+
486+
// Continue the task list with unchecked box
487+
const textBeforeCursor = lineText.substring(0, cursorInLine);
488+
const textAfterCursor = lineText.substring(cursorInLine);
489+
const newListItem = indent + marker + ' [ ] ';
490+
491+
view.dispatch({
492+
changes: {
493+
from: line.from,
494+
to: line.to,
495+
insert: textBeforeCursor + '\n' + newListItem + textAfterCursor
496+
},
497+
selection: {
498+
anchor: line.from + textBeforeCursor.length + 1 + newListItem.length
499+
}
500+
});
501+
return true;
502+
}
503+
504+
// Check for unordered list (- or *)
505+
const unorderedMatch = lineText.match(/^(\s*)([-*])\s+(.*)$/);
506+
if (unorderedMatch) {
507+
const [, indent, marker, content] = unorderedMatch;
508+
509+
// If the list item is empty (just the marker), remove it and exit list mode
510+
if (!content.trim()) {
511+
view.dispatch({
512+
changes: {
513+
from: line.from,
514+
to: line.to,
515+
insert: ''
516+
},
517+
selection: {
518+
anchor: line.from
519+
}
520+
});
521+
return true;
522+
}
523+
524+
// Continue the list
525+
const textBeforeCursor = lineText.substring(0, cursorInLine);
526+
const textAfterCursor = lineText.substring(cursorInLine);
527+
const newListItem = indent + marker + ' ';
528+
529+
view.dispatch({
530+
changes: {
531+
from: line.from,
532+
to: line.to,
533+
insert: textBeforeCursor + '\n' + newListItem + textAfterCursor
534+
},
535+
selection: {
536+
anchor: line.from + textBeforeCursor.length + 1 + newListItem.length
537+
}
538+
});
539+
return true;
540+
}
541+
542+
// Check for ordered list (1., 2., etc.)
543+
const orderedMatch = lineText.match(/^(\s*)(\d+)\.\s+(.*)$/);
544+
if (orderedMatch) {
545+
const [, indent, number, content] = orderedMatch;
546+
547+
// If the list item is empty (just the number), remove it and exit list mode
548+
if (!content.trim()) {
549+
view.dispatch({
550+
changes: {
551+
from: line.from,
552+
to: line.to,
553+
insert: ''
554+
},
555+
selection: {
556+
anchor: line.from
557+
}
558+
});
559+
return true;
560+
}
561+
562+
// Continue the list with incremented number
563+
const textBeforeCursor = lineText.substring(0, cursorInLine);
564+
const textAfterCursor = lineText.substring(cursorInLine);
565+
const nextNumber = parseInt(number, 10) + 1;
566+
const newListItem = indent + nextNumber + '. ';
567+
568+
view.dispatch({
569+
changes: {
570+
from: line.from,
571+
to: line.to,
572+
insert: textBeforeCursor + '\n' + newListItem + textAfterCursor
573+
},
574+
selection: {
575+
anchor: line.from + textBeforeCursor.length + 1 + newListItem.length
576+
}
577+
});
578+
return true;
579+
}
580+
581+
// Not a list, use default Enter behavior
582+
return false;
583+
};
584+
585+
export const listContinuationKeymap: KeyBinding[] = [
586+
{
587+
key: "Enter",
588+
run: handleEnterForListContinuation
589+
}
590+
];

workspaces/ballerina/ballerina-side-panel/src/components/editors/MultiModeExpressionEditor/ChipExpressionEditor/components/ChipExpressionEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { LineRange } from "@wso2/ballerina-core";
4949
import FXButton from "./FxButton";
5050
import { HelperPaneToggleButton } from "./HelperPaneToggleButton";
5151
import { HelperPane } from "./HelperPane";
52-
import { listContinuationKeymap } from "../../../../editors/ExpandedEditor/utils/codemirrorListContinuation";
52+
import { listContinuationKeymap } from "../../../ExpandedEditor/utils/templateUtils";
5353

5454
type HelperPaneState = {
5555
isOpen: boolean;
@@ -91,7 +91,7 @@ export type ChipExpressionEditorComponentProps = {
9191
onEditorViewReady?: (view: EditorView) => void;
9292
toolbarRef?: React.RefObject<HTMLDivElement>;
9393
enableListContinuation?: boolean;
94-
disableAutoOpenHelperPane? : boolean;
94+
disableAutoOpenHelperPane?: boolean;
9595
}
9696

9797
export const ChipExpressionEditorComponent = (props: ChipExpressionEditorComponentProps) => {

0 commit comments

Comments
 (0)