Why does ace editor load with all text highlighted and how to remove it?

前提是你 提交于 2019-12-07 04:56:56

问题


My code looks like :

$scope.aceIDEs='var hw = new function() {\n  console.log("Hello world!");\n}'

$scope.loadAceJSExample = function (_editor) {
_editor.setValue($scope.aceIDEs);
_editor.getSession().setUseWorker(false);
_editor.setHighlightActiveLine(true);
};

And:

<div class="container fade-in" style='padding: 4em;'>
<div>
      ui-ace="{onLoad : loadAceJSExample,
      onChange : aceJSExampleChanged,
      useWrapMode : true,
      theme : 'github',
      showGutter: true,
      mode: 'javascript'

    }" />

I tried calling _editor.getSession().removeMarker(); but did not help

Every time i refresh it looks like this,once i click in it returns to normal:


回答1:


Use _editor.session.setValue($scope.aceIDEs); which also resets undomanager. Alternatively you can use _editor.setValue($scope.aceIDEs, cursorPos);. where cursorPos=-1 puts cursor at start and cursorPos=1 at the end. Or call _editor.clearSelection() after setting value.



来源:https://stackoverflow.com/questions/22039568/why-does-ace-editor-load-with-all-text-highlighted-and-how-to-remove-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!