Ejemplo n.º 1
0
		// Inserts a string at the given position
		internal void InsertString (Line line, int pos, string s)
		{
			// Update our character count
			CharCount += s.Length;

			// Insert the text into the Line
			line.InsertString (pos, s);
		}
Ejemplo n.º 2
0
		// Insert text at the given position; use formatting at insertion point for inserted text
		internal void Insert (Line line, int pos, bool update_caret, string s, LineTag tag)
		{
			int break_index;
			int base_line;
			int old_line_count;
			int count = 1;
			LineEnding ending;
			Line split_line;
			
			// Don't recalculate while we mess around
			SuspendRecalc ();
			
			base_line = line.line_no;
			old_line_count = lines;

			// Discard chars after any possible -unlikely- end of file
			int eof_index = s.IndexOf ('\0');
			if (eof_index != -1)
				s = s.Substring (0, eof_index);

			break_index = GetLineEnding (s, 0, out ending, LineEnding.Hard | LineEnding.Rich);

			// There are no line feeds in our text to be pasted
			if (break_index == s.Length) {
				line.InsertString (pos, s, tag);
			} else {
				// Add up to the first line feed to our current position
				line.InsertString (pos, s.Substring (0, break_index + LineEndingLength (ending)), tag);
				
				// Split the rest of the original line to a new line
				Split (line, pos + (break_index + LineEndingLength (ending)));
				line.ending = ending;
				break_index += LineEndingLength (ending);
				split_line = GetLine (line.line_no + 1);
				
				// Insert brand new lines for any more line feeds in the inserted string
				while (true) {
					int next_break = GetLineEnding (s, break_index, out ending, LineEnding.Hard | LineEnding.Rich);
					
					if (next_break == s.Length)
						break;
						
					string line_text = s.Substring (break_index, next_break - break_index +
							LineEndingLength (ending));

					Add (base_line + count, line_text, line.alignment, tag.Font, tag.Color, ending);

					Line last = GetLine (base_line + count);
					last.ending = ending;

					count++;
					break_index = next_break + LineEndingLength (ending);
				}

				// Add the remainder of the insert text to the split
				// part of the original line
				split_line.InsertString (0, s.Substring (break_index));
			}
			
			// Allow the document to recalculate things
			ResumeRecalc (false);

			// Update our character count
			CharCount += s.Length;

			UpdateView (line, lines - old_line_count + 1, pos);

			// Move the caret to the end of the inserted text if requested
			if (update_caret) {
				Line l = GetLine (line.line_no + lines - old_line_count);
				PositionCaret (l, l.text.Length);
				DisplayCaret ();
			}
		}