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

The web page does not respond when deleting more than 400 lines of code using Ctrl+A #67

Closed
unitwk opened this issue Aug 1, 2021 · 4 comments

Comments

@unitwk
Copy link

unitwk commented Aug 1, 2021

Node: v14.15.1
OS: Windows 10

About 400 lines of Javascript code, select and delete all, and the whole page will be unresponsive for about 5 seconds.

Code:

import { CodeJar } from "codejar";
import { withLineNumbers } from "codejar/linenumbers";

import { highlight, languages } from "prismjs/components/prism-core";
import "prismjs/components/prism-clike";
import "prismjs/components/prism-javascript";
import "prismjs/themes/prism-tomorrow.css";

const editor = document.querySelector("#file-code-editor");
const highlightFunc = (editor) => {
    const code = editor.textContent;
    editor.innerHTML = highlight(code, languages.js);
 };
this.editor = CodeJar(editor, withLineNumbers(highlightFunc), {
    history: false,
    spellcheck: false,
    catchTab: false,
    preserveIdent: false,
    addClosing: false
});

Changing the highlightFunc function to this will solve this problem, but you will lose the text color.

  const highlightFunc = (editor) => {
      const code = editor.textContent;
      editor.innerHTML = code;
      // editor.innerHTML = highlight(code, languages.js);
    };

Is there any better way to solve this problem?

@antonmedv
Copy link
Owner

antonmedv commented Aug 1, 2021

CodeJar not designed as performant code editor, rather than small and lightweight.

Also, try to profile codejar, that is bottleneck?

@unitwk
Copy link
Author

unitwk commented Aug 1, 2021

Thank you for your reply.

I tried it under the official Demo and got the same result (https://medv.io/codejar/). I type 400 lines of Javascript in the code box of the web page and delete them all will also cause slow performance.

I don't know the exact reason, but it may be a performance problem caused by the removal of a large number of HTML elements at the same time.

@antonmedv
Copy link
Owner

Yes remove is expensive operation for DOM. I don’t know any ways to improve it.

@antonmedv
Copy link
Owner

Also it maybe issue with contenteditable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants