public void AddCharToCurrentLine(char c) { updateJustCurrentLine = true; bool passRemoveSelectedText = false; #if DEBUG if (dbugEnableTextManRecorder) { _dbugActivityRecorder.WriteInfo("TxLMan::AddCharToCurrentLine " + c); _dbugActivityRecorder.BeginContext(); } #endif if (SelectionRange != null) { #if DEBUG if (dbugEnableTextManRecorder) { _dbugActivityRecorder.WriteInfo(SelectionRange); } #endif RemoveSelectedText(); passRemoveSelectedText = true; } if (passRemoveSelectedText && c == ' ') { } else { commandHistory.AddDocAction( new DocActionCharTyping(c, textLineWriter.LineNumber, textLineWriter.ProperCharIndex)); } textLineWriter.AddCharacter(c); #if DEBUG if (dbugEnableTextManRecorder) { _dbugActivityRecorder.EndContext(); } #endif }
public void SetCurrentCharIndex(int newCharIndexPointTo) { #if DEBUG if (dbugTextManRecorder != null) { dbugTextManRecorder.WriteInfo("TextLineReader::CharIndex_set=" + newCharIndexPointTo); dbugTextManRecorder.BeginContext(); } #endif if (newCharIndexPointTo < 0 || newCharIndexPointTo > currentLine.CharCount) { throw new NotSupportedException("index out of range"); } if (newCharIndexPointTo == 0) { caret_char_index = 0; caretXPos = 0; rCharOffset = 0; rPixelOffset = 0; currentTextRun = currentLine.FirstRun; } else { int diff = newCharIndexPointTo - caret_char_index; switch (diff) { case 0: { return; } default: { if (diff > 0) { do { if (rCharOffset + currentTextRun.CharacterCount > newCharIndexPointTo) { caret_char_index = newCharIndexPointTo; caretXPos = rPixelOffset + currentTextRun.GetRunWidth(caret_char_index - rCharOffset); #if DEBUG if (dbugTextManRecorder != null) { dbugTextManRecorder.EndContext(); } #endif return; } } while (MoveToNextTextRun()); caret_char_index = rCharOffset + currentTextRun.CharacterCount; caretXPos = rPixelOffset + currentTextRun.Width; return; } else { do { if (rCharOffset - 1 < newCharIndexPointTo) { caret_char_index = newCharIndexPointTo; caretXPos = rPixelOffset + currentTextRun.GetRunWidth(caret_char_index - rCharOffset); #if DEBUG if (dbugTextManRecorder != null) { dbugTextManRecorder.EndContext(); } #endif return; } } while (MoveToPreviousTextRun()); caret_char_index = 0; caretXPos = 0; } } break; } } #if DEBUG if (dbugTextManRecorder != null) { dbugTextManRecorder.EndContext(); } #endif }