Giter VIP home page Giter VIP logo

Comments (10)

fijolekProjects avatar fijolekProjects commented on June 25, 2024 23

No need for hacks, you can also pass all completers via enableBasicAutocompletion as an Array, like so:

<AceEditor
  ...
  setOptions={{
    enableBasicAutocompletion: [this.yourCustomCompleter]
  }}
/>

from react-ace.

eemp avatar eemp commented on June 25, 2024 22

@andrerpena , I think it should be pretty easy to make happen (not taking into account the complexity of your custom completer). I can outline a quick example based on something similar I just did and looking around at ace docs.

In order to enable completion, we need to use an ace extension:

/* set up custom completer by using a ace extension */
import ace from 'brace'

/* figured out how to load the extension properly
 * by referring to ptmt's response in https://github.com/thlorenz/brace/issues/19
 */
import 'brace/ext/language_tools'
let langTools = ace.acequire('ace/ext/language_tools');

Setup the completer like this:

/* your custom completer */
var customCompleter = {
      getCompletions: function(editor, session, pos, prefix, callback) {
           // your code
           /* for example
            * let TODO = ...;
            * callback(null, [{name: TODO, value: TODO, score: 1, meta: TODO}]);
            */
      }
 }
langTools.addCompleter(customCompleter);

Currently, there is an existing issue (#59) dealing with how additional editor options should be handled. Without that I think we would need to hack it:

/* in some render somewhere
 * need this refs hack to set an editor option (another open issue in this repo)
 * inspired by elijahsmith's response in https://github.com/securingsincity/react-ace/issues/65
 */
<AceEditor ref="code" ...>

// with that setup, you can do something like
this.refs.code.editor.setOption('enableBasicAutocompletion', true);

I apologize if any of that is odd or poor practice. I am just starting out with react and just began using react-ace wrapper around ace. Although, almost all of it is based on the work of others.

Some other quick references/examples:

from react-ace.

blurymind avatar blurymind commented on June 25, 2024 3

how do we trigger autocompletion without ctrl+space. What if we want it to trigger automatically

from react-ace.

andrerpena avatar andrerpena commented on June 25, 2024

@eemp Sorry for the late response and thank you very much for the example. This seems fairly easy indeed. I'll try it. Thanks again.

from react-ace.

go299 avatar go299 commented on June 25, 2024

I added my own ompleter, but I need to press ctr+space to show the competion, Is there a way to show the completion automatically.

from react-ace.

hristo-vrigazov avatar hristo-vrigazov commented on June 25, 2024

@go299 You just have to enable the option enableLiveAutocompletion in ace.

from react-ace.

oakland avatar oakland commented on June 25, 2024

@fijolekProjects How to write a custom completer? Is there any docs about this?

from react-ace.

fijolekProjects avatar fijolekProjects commented on June 25, 2024

@oakland Don't know about docs, but here's working example https://github.com/TouK/nussknacker/blob/v0.0.9/ui/client/components/graph/ExpressionSuggest.js#L31
Basically it's an object with getCompletions method implemented. Hope it helps

from react-ace.

oakland avatar oakland commented on June 25, 2024

@fijolekProjects Thanks a lot! I will try it out in my project.

from react-ace.

lashax avatar lashax commented on June 25, 2024

how do we trigger autocompletion without ctrl+space. What if we want it to trigger automatically

Set enableLiveAutocompletion option to true.

from react-ace.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.