Comments (10)
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.
@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:
- Ace doc on enabling completion - they also have an example of a custom rhyme completer linked to at the bottom of the doc
- Ace demo with completion - ctrl+space activates completion
from react-ace.
how do we trigger autocompletion without ctrl+space. What if we want it to trigger automatically
from react-ace.
@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.
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.
@go299 You just have to enable the option enableLiveAutocompletion
in ace.
from react-ace.
@fijolekProjects How to write a custom completer? Is there any docs about this?
from react-ace.
@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.
@fijolekProjects Thanks a lot! I will try it out in my project.
from react-ace.
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)
- Expand collapse buttons not accessible via tab (Read only mode)
- Issue with CSP HOT 1
- Horizontal scrollbar is not visible
- 指定mode时出现network报错
- editor focus comes out again and agian on onChange() while setState HOT 2
- Merge PR
- Move to React 17/18?
- Changing editor sessions causes session/selection listeners to stop firing
- Unable to fully display content when line length is too long HOT 1
- ace在多个微应用间,通过组件渲染切换,css样式丢失 HOT 3
- expected expression, got '<' HOT 1
- No System Verilog Support
- import 'ace-builds/src-noconflict/mode-javascript';
- State is equal to it's default value on commands exec function call HOT 2
- Are mode and theme imports required for react-ace?
- Problem with so many lines of code (10k lines of JSON)
- Textarea has not attr "name"
- How to dynamically import modes and themes ?
- ace is not defined in production only
- Missing spaces in auto-complete
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-ace.