Skip to content

Commit

Permalink
Relaxed bookmarks setting to allow more than 1 bookmark per the same …
Browse files Browse the repository at this point in the history
…line.
  • Loading branch information
Sergey M committed Jan 22, 2020
1 parent c120049 commit 4d2b97e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
14 changes: 4 additions & 10 deletions DPackRx.Tests/Features/BookmarksServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,11 @@ public void SetBookmark_SameLine()
var repeatResult = service.SetBookmark(1);

var bookmarks = service.GetFileBookmarks("test");
var bookmark = bookmarks.FirstOrDefault();

Assert.That(result, Is.True);
Assert.That(repeatResult, Is.False);
Assert.That(repeatResult, Is.True);
Assert.That(bookmarks, Is.Not.Null);
Assert.That(bookmarks.Count(), Is.EqualTo(1));
Assert.That(bookmark, Is.Not.Null);
Assert.That(bookmark.Number, Is.EqualTo(5));
Assert.That(bookmarks.Count(), Is.EqualTo(2));
}

[Test]
Expand Down Expand Up @@ -525,14 +522,11 @@ public void SetGlobalBookmark_SameLine()
var repeatResult = service.SetGlobalBookmark(1);

var bookmarks = service.GetFileBookmarks("test");
var bookmark = bookmarks.FirstOrDefault();

Assert.That(result, Is.True);
Assert.That(repeatResult, Is.False);
Assert.That(repeatResult, Is.True);
Assert.That(bookmarks, Is.Not.Null);
Assert.That(bookmarks.Count(), Is.EqualTo(1));
Assert.That(bookmark, Is.Not.Null);
Assert.That(bookmark.Number, Is.EqualTo(5));
Assert.That(bookmarks.Count(), Is.EqualTo(2));
}

[Test]
Expand Down
14 changes: 1 addition & 13 deletions DPackRx/Features/Bookmarks/BookmarksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,7 @@ public bool SetBookmark(int number)
_bookmarks.Add(fileName, bookmarks);
}

// 1 bookmark per line check
var bookmark = bookmarks.FirstOrDefault(b => (b.Number != number) && (b.Type == BookmarkType.Local) && (GetBookmarkLine(fileName, b) == position.Line));
if (bookmark != null)
return false;

bookmark = bookmarks.FirstOrDefault(b => (b.Number == number) && (b.Type == BookmarkType.Local));
var bookmark = bookmarks.FirstOrDefault(b => (b.Number == number) && (b.Type == BookmarkType.Local));
if (bookmark != null)
{
var line = GetBookmarkLine(fileName, bookmark);
Expand Down Expand Up @@ -301,13 +296,6 @@ public bool SetGlobalBookmark(int number)
if (position.IsEmpty())
return false;

// 1 bookmark per line check
foreach (var file in _bookmarks.Keys)
{
if (_bookmarks[file].FirstOrDefault(b => (b.Type == BookmarkType.Global) && (GetBookmarkLine(file, b) == position.Line)) != null)
return false;
}

// Find existing global bookmark and file it's in
var bookmarkFileName = string.Empty;
Bookmark bookmark = null;
Expand Down

0 comments on commit 4d2b97e

Please sign in to comment.