English 中文(简体)
我怎么能与安执委会编辑一道突出守则。
原标题:How can I highlight code with ACE editor?
最佳回答
问题回答

突出字句:

var range = new Range(rowStart, columnStart, rowEnd, columnEnd);
var marker = editor.getSession().addMarker(range,"ace_selected_word", "text");

删除突出字句:

editor.getSession().removeMarker(marker);

着重说明:

editor.getSession().addMarker(range,"ace_active_line","background");

我首先要宣布您的行号为全球变量。

var erroneousLine;

这一点很重要。 负功能,以直线编号(lineNumber)作为其参数。 可以通过错误信息或使用<代码>editor.selection.getCursor(.row,以获得目前行文或其他东西。

function highlightError(lineNumber) {
  unhighlightError();
  var Range = ace.require("ace/range").Range
  erroneousLine = editor.session.addMarker(new Range(lineNumber, 0, lineNumber, 144), "errorHighlight", "fullLine");
}

Notice that I have declared a errorHighlight, which is how this will be highlighted. In your css place the following:

.errorHighlight{
  position:absolute;
  z-index:20;
  background-color:#F4B9B7;
}

This function unhighlights the already highlighted line

function unhighlightError(){
  editor.getSession().removeMarker(erroneousLine);
}

想法:

function highlightSyntax(text) {
    var res = [];

    var Tokenizer = ace.require( ace/tokenizer ).Tokenizer;
    var Rules = ace.require( ace/mode/sql_highlight_rules ).SqlHighlightRules;
    var Text = ace.require( ace/layer/text ).Text;

    var tok = new Tokenizer(new Rules().getRules());
    var lines = text.split( 
 );

    lines.forEach(function(line) {
      var renderedTokens = [];
      var tokens = tok.getLineTokens(line);

      if (tokens && tokens.tokens.length) {
        new Text(document.createElement( div )).$renderSimpleLine(renderedTokens, tokens.tokens);
      }

      res.push( <div class="ace_line">  + renderedTokens.join(  ) +  </div> );
    });

    return  <div class="ace_editor ace-tomorrow"><div class="ace_layer" style="position: static;">  + res.join(  ) +  </div></div> ;
}

这一职能应当强调特定文本中的Syntax(代相传的主题),而不装上整个编辑,也不加特。

I think this is very late to answer, but I will still write in case it can help others.

我最后在文字方面创建了一个简单的功能,在范围上可以进行协调,以突出和充实:

highlighText(text: string) {
    const value = this.aceEditor.session.getValue();
    const startRow = value.substr(0, value.indexOf(text)).split(/
|
|
/).length - 1;
    const startCol = this.aceEditor.session.getLine(startRow).indexOf(text);
    const endRowOffset = text.split(/
|
|
/).length;
    const endRow = startRow + endRowOffset - 1;
    const endCollOffset = text.split(/
|
|
/)[endRowOffset - 1].length;
    const endCol = startCol + (endCollOffset > 1 ? endCollOffset + 1 : endCollOffset);
    const range = new ace.Range(startRow, startCol, endRow, endCol);

    this.aceEditor.session.selection.setRange(range);
    this.aceEditor.scrollToLine(startRow, true, true, () => {});
  }




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签