public void MoveLineMarker() { int preRows = (string.IsNullOrEmpty(preCode) ? 0 : preCode.Split('\n').Length) + 1; int selected = preRows + IDEPARSER.calcCurrentSelectedLine(theInputField.caretPosition, theInputField.text); IDELineMarker.SetIDEPosition(selected); }
public static bool validateText(string fullText, int maxLines, int maxPerLine) { List <string> preCodeTextLines = IDEPARSER.parseIntoLines(PMWrapper.preCode); var preCodeLineCount = countCodeLines(preCodeTextLines); List <string> mainCodeTextLines = IDEPARSER.parseIntoLines(fullText); var mainCodeLineCount = countCodeLines(mainCodeTextLines); Progress.Instance.LevelData[PMWrapper.CurrentLevel.id].CodeLineCount = mainCodeLineCount + preCodeLineCount; UISingleton.instance.rowsLimit.UpdateRowsLeft(mainCodeLineCount, maxLines); if (mainCodeLineCount > maxLines) { // Too many rows UISingleton.instance.rowsLimit.redness = 1; return(false); } foreach (string t in mainCodeTextLines) { if (lineSize(t) > maxPerLine) { return(false); } } return(true); }
public void InsertText(string newText, bool smartButtony = false) { if (theInputField.isFocused) { // If selection, replace selection // Else, just insert int start = Mathf.Min(theInputField.selectionAnchorPosition, theInputField.selectionFocusPosition); int end = Mathf.Max(theInputField.selectionAnchorPosition, theInputField.selectionFocusPosition); string checkText; if (start == end) { // No selection checkText = theInputField.text.Insert(start, newText); } else { // Yes selection checkText = theInputField.text.Substring(0, start) + newText + theInputField.text.Substring(end); } // Try adding extra newline if it's the end of the line string checkText2 = null; string after = checkText.Substring(start + newText.Length); if (smartButtony && (after.Length == 0 || after[0] == '\n')) { int indent = IDEPARSER.getIndentLevel(start, checkText); // Add newline directly if (start > 0 && checkText[start - 1] == ':') { checkText = checkText.Insert(start, "\n" + new string('\t', indent)); start += 1 + indent; } checkText2 = checkText.Insert(start + newText.Length, "\n" + new string('\t', indent)); start += 1 + indent; } // Check if it fits if (checkText2 == null || !IDETextManipulation.validateText(checkText2, codeRowsLimit, maxChars)) { checkText2 = null; if (!IDETextManipulation.validateText(checkText, codeRowsLimit, maxChars)) { checkText = null; } } // One of them succeded if (checkText2 != null || checkText != null) { inserting = true; setNewCaretPos(start + newText.Length); theInputField.text = checkText2 ?? checkText; } } }
public void FocusCursor() { Canvas.ForceUpdateCanvases(); int preCodeLines = preCode.Length == 0 ? 0 : preCode.Split('\n').Length; theScrollLord.FocusOnLineNumber(IDEPARSER.calcCurrentSelectedLine(theInputField.selectionAnchorPosition, theInputField.text) + preCodeLines); MoveLineMarker(); }
public void MoveLineMarker() { if (PMWrapper.IsDemoingLevel) { IDELineMarker.instance.SetState(IDELineMarker.State.Hidden); } else { int preRows = (string.IsNullOrEmpty(preCode) ? 0 : preCode.Split('\n').Length) + 1; int selected = preRows + IDEPARSER.calcCurrentSelectedLine(theInputField.caretPosition, theInputField.text); IDELineMarker.SetIDEPosition(selected); } }
public static char MyValidate(char c, int charIndex, bool isPasting, List <IndentLevel> toAddLevels, string currentText, IDETextField theTextField) { if (isPasting) { return(c); } if (c == '\n') { toAddLevels.Clear(); toAddLevels.Add(new IndentLevel(charIndex, IDEPARSER.getIndentLevel(charIndex, currentText))); theTextField.setNewCaretPos(toAddLevels[0].getNewCaretPos()); return('\n'); } return(c); }
public static bool validateText(string fullText, int maxLines, int maxPerLine) { List <string> textLines = IDEPARSER.parseIntoLines(fullText); UISingleton.instance.rowsLimit.UpdateRowsLeft(textLines.Count, maxLines); if (textLines.Count > maxLines) { // Too many rows UISingleton.instance.rowsLimit.redness = 1; return(false); } foreach (string t in textLines) { if (lineSize(t) > maxPerLine) { return(false); } } return(true); }
public void selectEndOfLine(int lineNumber) { theTextField.setNewCaretPos(IDEPARSER.calcSelectedLineLastIndex(lineNumber, theInputField.text)); }