public static async Task <Position> getEndOfTag(string tagName, BlazorMonaco.Range tagRange, TextModel model) { string endTag = $"</{tagName}>"; int l = tagRange.EndLineNumber; List <string> lines = await model.GetLinesContent(); int endTagCol = -1; while (l < lines.Count) {//problem if previous tag closes on the same line before the start of current tag if (l == tagRange.EndLineNumber) { endTagCol = lines[l - 1].IndexOf(endTag, tagRange.EndColumn - 1); //searching on first line } else { endTagCol = lines[l - 1].IndexOf(endTag); } if (endTagCol > -1) { break; } l++; } return(new Position() { Column = endTagCol + endTag.Length + 1, LineNumber = l }); }
public static async Task markWholeTag( string tagName, Position pClick, bool isLeftButton, MonacoEditor editor, Dictionary <string, BlazorMonaco.Range> sourceDecorations) { { if (isLeftButton) { KeyValuePair <string, BlazorMonaco.Range> dec = (from d in sourceDecorations where IsPosInRange(pClick, d.Value) select d).FirstOrDefault(); if (string.IsNullOrEmpty(dec.Key)) { //clicking outside a marked tag - clear previous selection in currentRangeID await Helpers.RemoveDecoration(editor, currentRangeId); currentDec = new KeyValuePair <string, BlazorMonaco.Range>(); } else { TextModel sourceModel = await editor.GetModel(); string tag = await sourceModel.GetValueInRange(dec.Value, EndOfLinePreference.CRLF); Position pEnd; if (IsClosedTag(tag)) { pEnd = new Position() { Column = dec.Value.EndColumn, LineNumber = dec.Value.EndLineNumber } } ; else { pEnd = await getEndOfTag(tagName, dec.Value, sourceModel); } BlazorMonaco.Range range = new BlazorMonaco.Range() { StartColumn = dec.Value.StartColumn, StartLineNumber = dec.Value.StartLineNumber, EndColumn = pEnd.Column, EndLineNumber = pEnd.LineNumber }; currentRangeId = await Helpers.ColorRange(editor, range, currentRangeId, enmStatusColor.Current); currentDec = dec; } } } }
public static async Task <string> ColorRange(MonacoEditor editor, BlazorMonaco.Range range, string id = "", enmStatusColor statusColor = enmStatusColor.Done) { string contentClass = ""; string GlyphMarginClass = ""; string MiniMapColor = ""; switch (statusColor) { case enmStatusColor.Done: contentClass = "decorationContentDone"; GlyphMarginClass = "decorationGlyphMarginDone"; MiniMapColor = "#90EE90"; break; case enmStatusColor.Current: contentClass = "decorationContentCurrent"; GlyphMarginClass = "decorationGlyphMarginCurrent"; MiniMapColor = "#bbfaf9"; break; } string[] targetID = new string[] { }; if (!string.IsNullOrEmpty(id)) { targetID = new string[] { id }; } List <ModelDeltaDecoration> newDec = new List <ModelDeltaDecoration>() { new ModelDeltaDecoration { Range = range, Options = new ModelDecorationOptions { IsWholeLine = false, ClassName = contentClass, GlyphMarginClassName = GlyphMarginClass, Minimap = new ModelDecorationMinimapOptions() { Position = MinimapPosition.Inline, Color = MiniMapColor } } } }; string[] decorations = await editor.DeltaDecorations(targetID, newDec.ToArray()); return(decorations[0]); }
public static bool IsPosInRange(Position position, BlazorMonaco.Range range) { //before or after range lines if (position.LineNumber < range.StartLineNumber || position.LineNumber > range.EndLineNumber) { return(false); } //on first range line before range start column if (position.LineNumber == range.StartLineNumber && position.Column < range.StartColumn) { return(false); } //on last range line after last range column if (position.LineNumber == range.EndLineNumber && position.Column > range.EndColumn) { return(false); } return(true); //all else }
public static async Task <BlazorMonaco.Range> ExpandTagRange(BlazorMonaco.Range matchRange, TextModel model) { BlazorMonaco.Range newRange = new BlazorMonaco.Range() { StartColumn = matchRange.StartColumn, StartLineNumber = matchRange.StartLineNumber }; int tagCloseLine = matchRange.EndLineNumber; Position endPos = await getClosingPosition(model, matchRange.EndLineNumber, matchRange.EndColumn - 1); newRange.EndColumn = endPos.Column; newRange.EndLineNumber = endPos.LineNumber; return(newRange); //local non static recursive method async Task <Position> getClosingPosition(TextModel model, int lineNum, int colNum) { Position pos = new Position(); string line = await model.GetLineContent(lineNum); int tagCloseCol = line.IndexOf(">", colNum); if (tagCloseCol == -1) //not found { pos = await getClosingPosition(model, lineNum + 1, 0); } else { pos.Column = tagCloseCol + 2; pos.LineNumber = lineNum; } return(pos); } }