Add() public method

public Add ( Position position ) : void
position Position
return void
Ejemplo n.º 1
0
 public void Insert(EditorInsertMessage message)
 {
     GoTo(new Location(
         message.Destination.File,
         message.Destination.Line,
         message.Destination.Column));
     var location = getLocation();
     if (location == null)
         return;
     var newline = "\\n";
     if (Environment.OSVersion.Platform != PlatformID.Unix &&
         Environment.OSVersion.Platform != PlatformID.MacOSX)
         newline = "\\r\\n";
     var content = runFunction("{0}:getText", location.Buffer.ID);
     if (content == null)
         return;
     var lines = content.Split(new[] { newline }, StringSplitOptions.None);
     if (lines.Length < location.Line)
     {
         Logger.Write("Asked for line {0} but document only contained {1} lines",
             location.Line,
             lines.Length);
         return;
     }
     var line = lines[location.Line - 1];
     if (line.Length < location.Column)
     {
         Logger.Write("Asked for column {0} but line was only {1} chars long",
             location.Column,
             line);
         return;
     }
     var insertColumn = location.Column; // + ((message.Destination.Column - 1) - location.Column);
     var lineModified =
         line.Substring(0, insertColumn) +
         message.Text
             .Replace(Environment.NewLine, newline)
             .Replace("\"", "\\\"") +
         line.Substring(insertColumn, line.Length - insertColumn);
     var length = line.Length;
     var lastLine = location.Line != lines.Length - 1;
     if (lastLine)
         length += newline.Length;
     send("{0}:remove/0 {1} {2}",
         location.Buffer.ID,
         location.Offset - location.Column,
         length - 1);
     send("{0}:insert/0 {1} \"{2}\"",
         location.Buffer.ID,
         location.Offset - location.Column,
         lineModified);
     if (message.MoveOffset != null)
     {
         var offsetLocation = new Location(
             message.Destination.File,
             message.Destination.Line,
             message.Destination.Column);
         offsetLocation.Add(message.MoveOffset);
         GoTo(offsetLocation);
     }
     else
     {
         GoTo(new Location(
             message.Destination.File,
             message.Destination.Line,
             message.Destination.Column + message.Text.Length));
     }
 }
Ejemplo n.º 2
0
        public void Insert(EditorInsertMessage message)
        {
            var origin = getLocation();
            GoTo(new Location(
                message.Destination.File,
                message.Destination.Line,
                message.Destination.Column));
            var location = getLocation();
            if (location == null)
                return;
            var newline = "\\n";
            if (Environment.OSVersion.Platform != PlatformID.Unix &&
                Environment.OSVersion.Platform != PlatformID.MacOSX)
                newline = "\\r\\n";
            var content = getText(location.Buffer.ID);
            if (content == null)
                return;
            var lines = content.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            if (lines.Length < location.Line)
            {
                Logger.Write("Asked for line {0} but document only contained {1} lines",
                    location.Line,
                    lines.Length);
                return;
            }
            var line = lines[location.Line - 1];
            if (line.Length < location.Column)
            {
                Logger.Write("Asked for column {0} but line was only {1} chars long",
                    location.Column,
                    line);
                return;
            }

            Logger.Write("Line is: " + line);
            var removeLength = line.Length - message.Destination.Column + 1;
            if (removeLength > line.Length)
                removeLength = line.Length;
            var insertColumn = location.Column; // + ((message.Destination.Column - 1) - location.Column);
            var textModified =
                message.Text
                    .Replace("\\", "\\\\")
                    .Replace("\"", "\\\"")
                    .Replace(Environment.NewLine, newline) +
                line.Substring(insertColumn, removeLength);
            //send("{0}:remove/0 {1} {2}",
            //	location.Buffer.ID,
            //	location.Offset - location.Column,
            //	length - 1);
            //send("{0}:insert/0 {1} \"{2}\"",
            //	location.Buffer.ID,
            //	location.Offset - location.Column,
            //	lineModified);
            send("{0}:remove/0 {1} {2}",
                location.Buffer.ID,
                location.Offset,
                removeLength);
            send("{0}:insert/0 {1} \"{2}\"",
                location.Buffer.ID,
                location.Offset,
                textModified);
            if (message.MoveOffset != null)
            {
                var offsetLocation = new Location(
                    message.Destination.File,
                    message.Destination.Line,
                    message.Destination.Column);
                offsetLocation.Add(message.MoveOffset);
                GoTo(offsetLocation);
            }
            else
            {
                if (origin == null)
                    return;
                var originAdjusted = origin.Line;
                if (origin.Line > message.Destination.Line) {
                    originAdjusted =
                        origin.Line +
                        message.Text.Split(new[] {Environment.NewLine}, StringSplitOptions.None).Length;
                }
                GoTo(new Location(
                    origin.Buffer.Fullpath,
                    origin.Line,
                    origin.Column));
            }
        }