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

Unexpected Behaviour On Snippets, When Moving Cursor Using <Tab> #363

Closed
atpur-rafif opened this issue Jul 29, 2022 · 6 comments
Closed

Comments

@atpur-rafif
Copy link

When we're using snippets autocompletion with multiple placeholder, and key are used to move between placeholder as expected on codemirror demo website
codemirror
Link

While in @uiw/react-codemirror, unexpected behaviour happen. Instead move to next placeholder, key will add '\t' to start of the line.
@uiw/reac-codemirror
Link

Extension used in codemirror website (src):

  extensions: [
    basicSetup,
    javascript(),
    javascriptLanguage.data.of({autocomplete: jsCompletion})
  ]
@atpur-rafif atpur-rafif changed the title Unexpected Behaviour On Snippets Cursor Move Using <Tab> Unexpected Behaviour On Snippets, When Moving Cursor Using <Tab> Jul 29, 2022
@jaywcjlove
Copy link
Member

@atpur-rafif
Copy link
Author

atpur-rafif commented Jul 29, 2022

I guess you were right, the real reason why I did submit this issue is because I want to make custom snippet like this. And working as expected. (I am still not sure why on this website doesn't work as expected on my computer)

In the meantime, if you have spare time. Can you check where I did wrong?
image
image

Result:
A

@jaywcjlove
Copy link
Member

I preview your example, is the expected behavior.

Is it a browser compatibility issue?

@JustIdentity

@atpur-rafif
Copy link
Author

atpur-rafif commented Jul 29, 2022

Found out the problem, the reason why it's resetting is because I use setter. So the whole element re-rendered. And probably that's the reason why the website didn't work (Code).

@jaywcjlove
Copy link
Member

import React from "react";
import CodeMirror from "@uiw/react-codemirror";
import { snippetCompletion } from "@codemirror/autocomplete";
import { markdown, markdownLanguage } from "@codemirror/lang-markdown";

export default function App() {
  return (
    <div>
      <CodeMirror
        value="console.log('hello world!');"
        height="200px"
        extensions={[
          markdown(),
          markdownLanguage.data.of({
            autocomplete: [
              snippetCompletion("hello(${1}, ${2}) ${}", { label: "hello" })
            ]
          })
        ]}
        onChange={(value, viewUpdate) => {
          console.log("value:", value);
        }}
      />
    </div>
  );
}

@atpur-rafif
Copy link
Author

atpur-rafif commented Jul 29, 2022

I think I will refactor CodeMirror Element, so it won't re-render every time the value change. Btw, thanks for the hardwork

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