[英]Get indentation used in specific line in CodeMirror
我正在使用CodeMirror,並且想提供一些簡單的代碼轉換功能。
不過,我需要知道的是我所在行的縮進,例如:
function test() {
var x = 0; //I need to get that this line has 2 spaces.
var y = function() {
return true; //And that this one has 4 spaces -or a tab.
}
}
是否有通過CodeMirror API進行此操作的標准方法,或者有任何相關的技巧來進行獲取?
由於CodeMirror主要用於語法分析(令牌等),因此我嘗試分析行令牌並將其與游標數據結合起來,但我想要求更徹底,更清晰的內容。
令牌的狀態包含indented
屬性,該屬性為令牌的縮進提供以下信息:
var token = editor.getTokenAt(editor.getCursor());
console.log(token.state.indented);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.