javascript - 如何使用 Angular Controller 中的 ACE 编辑器将文本插入到特定位置

标签 javascript angularjs ace-editor

我正在 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/

相关文章:

javascript - Yii2 - i18n 用于 js 验证消息中的 {attribute}

javascript - Angular 语法错误 : missing ; before statement

javascript - Stripe checkout 在 Angular 1.x 中不起作用

html - 获取 HTML 元素的行号

ace-editor - 如何在 ace 编辑器中使用 (.) 句点和 Ctrl 空格触发两个不同的自定义自动完成

java - 从 JavaFX WebView 中的 Ace Editor 获取代码

javascript - CSS 过渡不适用于 classList.add

javascript - 关于鼠标光标移动,我可以 "trick"jQuery Draggable 吗?

javascript - 哪个是第一个被调用的?构造函数或 componentDidMount 或 Render

javascript - 从服务获取数据