我正在 Ace 内开发实时协作编辑器编辑器,我找不到任何有关在编辑器中的特定位置插入文本的文档。
实际上我想在用户单击按钮时在光标位置添加文本。
我使用以下代码:
<div ui-ace="aceOptions" ng-model="content"></div>
在 Angular Controller 中我使用了以下代码,
$scope.aceOptions = {
mode : 'Javascript',
theme : 'dreamweaver'
};
//content of ace editor
$scope.content = "test";
//user button click for adding text
$scope.addTextOnClick = function(){
//Here i have to get current cursor and needs to insert text
//Which map to content and insert into it
}
请帮我解决这个问题。
最佳答案
您可以通过 Edit.getCurrentPosition 获取光标位置方法。
例如,之后您可以使用该位置计算文本中的位置并向该文本插入一些内容。
我还建议查看Ace docs .
以下是获取编辑器实例的方法:https://github.com/angular-ui/ui-ace#ace-instance-direct-access 。
the $scope.aceLoaded function will be called with the Ace Editor instance as first argument
查看此标题下面的示例。
关于javascript - 如何使用 Angular Controller 中的 ACE 编辑器将文本插入到特定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45838224/