Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JIMT][CT-482] - fixed editor jumping #57867

Merged
merged 2 commits into from
Apr 8, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/src/lab2/views/components/editor/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const CodeEditor: React.FunctionComponent<CodeEditorProps> = ({
// When we have a new channelId and/or start code, reset the editor with the start code.
// A new channelId means we are loading a new project, and we need to reset the editor.
useEffect(() => {
if (editorView) {
if (editorView && editorView.state.doc.toString() !== startCode) {
editorView.dispatch({
changes: {
from: 0,
Expand Down
11 changes: 8 additions & 3 deletions apps/src/weblab2/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback} from 'react';
import React, {useCallback, useMemo} from 'react';

import {editableFileType} from '@cdoide/utils';
import {useCDOIDEContext} from '@cdoide/cdoIDEContext';
Expand Down Expand Up @@ -26,7 +26,12 @@ const Editor = () => {
(value: string) => {
saveFile(file.id, value);
},
[file, saveFile]
[file.id, saveFile]
);

const editorConfigExtensions = useMemo(
() => [codeMirrorLangMapping[file.language]],
[file.language]
Comment on lines +29 to +34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some minor memoization tweaks to ensure that repackaged props aren't handed down to the editor

);

if (!editableFileType(file.language)) {
Expand All @@ -41,7 +46,7 @@ const Editor = () => {
darkMode={true}
onCodeChange={onChange}
startCode={file.contents}
editorConfigExtensions={[codeMirrorLangMapping[file.language]]}
editorConfigExtensions={editorConfigExtensions}
/>
)}
</div>
Expand Down