Skip to content

Commit

Permalink
fix: fix marker bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vault-developer committed Aug 30, 2024
1 parent 022d809 commit 6b9a8e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/components/Editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ const codeByTitle = codeExamples.reduce(
);

function EditorComponent() {
const [text, setText] = useState(codeExamples[0].code);
const [text, setText] = useState(codeExamples[3].code);
const eventListsStateSet = useEventLists((state) => state.set);
const eventListsStateClear = useEventLists((state) => state.clear);
const clearAnimationState = useEventLoopAnimation((state) => state.clear);
const setAnimationState = useEventLoopAnimation((state) => state.setState);
const status = useEventLoopAnimation((state) => state.status);
const [example, setExample] = useState(codeExamples[0].title);
const [example, setExample] = useState(codeExamples[3].title);
const speedFactorState = useSpeedFactor((state) => state);
const setEditorRef = useEditor((state) => state.setRef);
const setSourceCode = useEditor((state) => state.setSource);
const clearEditor = useEditor((state) => state.clearEditor);
const editorRef = useRef<AceEditor>(null);

const onSelect = (e: SelectChangeEvent) => {
Expand All @@ -51,6 +52,7 @@ function EditorComponent() {
const onStop = () => {
clearAnimationState();
eventListsStateClear();
clearEditor();
};

const onPause = () => {
Expand Down
12 changes: 8 additions & 4 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export const useEditor = create<EditorInterface>((set, get) => ({
source: '',
setSource: (source) => set({ source }),
markers: [],
clearEditor: () => {
const markers = get().markers;
if (markers.length > 0) {
markers.pop();
}
get().clearOldMarkers();
get().setSource('');
},
clearOldMarkers: () => {
if (!get().ref?.current?.editor) return;
const session = get().ref!.current!.editor.getSession();
Expand All @@ -108,10 +116,6 @@ export const useEditor = create<EditorInterface>((set, get) => ({
session.addMarker(range, 'selected_lines', 'text');
},
pushMarker: ([start, end]) => {
const markers = get().markers;
if (markers.length > 0) {
markers.pop();
}
get().markers.push([start, end]);
get().clearOldMarkers();
get().drawLatestMarker();
Expand Down
1 change: 1 addition & 0 deletions src/store/store.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface EditorInterface {
setSource(source: string): void;
pushMarker(range: [number, number]): void;
popMarker(): void;
clearEditor(): void;
clearOldMarkers(): void;
drawLatestMarker(): void;
markers: [number, number][];
Expand Down

0 comments on commit 6b9a8e1

Please sign in to comment.