2017-08-23 43 views
0

我正在編輯Ace編輯器中的實時協作編輯器,在編輯器的某個位置上找不到任何有關插入文本的文檔。如何使用Angular Controller的ACE編輯器將文本插入特定位置

其實我想在用戶點擊按鈕時在光標位置添加文本。

我一直在使用下面的代碼:

<div ui-ace="aceOptions" ng-model="content"></div> 

而在角控制器我用下面的代碼,

$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 
} 

請幫我解決這個問題。

+0

嘗試使用ng-bind。你不能在div標籤上使用ng-model – Vivz

回答

1

您可以使用Edit.getCurrentPosition方法獲取光標位置。

之後,例如,您可以在該位置的文本中計算位置並在該文本中插入某些內容。

我也建議檢查出Ace docs

以下是如何獲取編輯器實例:https://github.com/angular-ui/ui-ace#ace-instance-direct-access

的$ scope.aceLoaded功能將與王牌編輯器實例被稱爲第一個參數

退房比如這個標題下。

+0

是的,我已經使用過,很抱歉,請告訴我如何得到編輯器的編輯,因爲我已經用作指令 –

+0

我已經說過:嘗試閱讀文檔。我更新了我的答案以及如何獲取編輯器實例。 –

+0

謝謝,得到了解決方案 –

相關問題