Skip to content

Commit 2b0cb0b

Browse files
tommckmadskristensen
authored andcommitted
Fixed 2 bugs related to madskristensen#6 (madskristensen#25)
Fixed error throw when saving a non-supported file type Fixed throw when the current cursor position is greater that the resulting reformatted file length
1 parent d379368 commit 2b0cb0b

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎src/Commands/PrettierCommand.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public async Task<bool> MakePrettierAsync()
6767
undo.Complete();
6868
}
6969

70-
var newSnapshotPoint = new SnapshotPoint(_view.TextBuffer.CurrentSnapshot, snapshotPoint.Position.Position);
70+
var currSnapShot = _view.TextBuffer.CurrentSnapshot;
71+
var newSnapshotPoint = new SnapshotPoint(currSnapShot, Math.Min(snapshotPoint.Position.Position, currSnapShot.Length));
7172
_view.Caret.MoveTo(newSnapshotPoint);
7273
_view.ViewScroller.EnsureSpanVisible(new SnapshotSpan(newSnapshotPoint, 0));
7374

‎src/RunningDocTableEventsHandler.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public int OnBeforeSave(uint docCookie)
4747
return VSConstants.S_OK;
4848
}
4949

50-
PrettierCommand cmd = wpfTextView.Properties.GetProperty<PrettierCommand>("prettierCommand");
51-
if (cmd != null)
50+
PrettierCommand cmd;
51+
if (wpfTextView.Properties.TryGetProperty<PrettierCommand>("prettierCommand", out cmd))
5252
{
5353
ThreadHelper.JoinableTaskFactory.Run(() => cmd.MakePrettierAsync());
5454
}

0 commit comments

Comments
 (0)