-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unified_diffs class and F7, F8 key to iterate
- Loading branch information
Showing
11 changed files
with
246 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Name: unified-diffs.h | ||
// Purpose: Declaration of class unified_diffs | ||
// Author: Anton van Wezenbeek | ||
// Copyright: (c) 2024 Anton van Wezenbeek | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#include <set> | ||
|
||
namespace wex | ||
{ | ||
class stc; | ||
class unified_diff; | ||
|
||
/// Offers a class that collects unified diff invocations to be able | ||
/// to iterate through the differences and show them on stc component. | ||
class unified_diffs | ||
{ | ||
public: | ||
/// Constructor, provide stc. | ||
unified_diffs(stc* s); | ||
|
||
/// Clears all differences, reset iterator. | ||
void clear(); | ||
|
||
/// Returns distance of the iterator to begin of collection. | ||
int distance() const; | ||
|
||
/// Goto first diff line on stc. | ||
bool first(); | ||
|
||
/// Inserts a unified diff. | ||
void insert(const unified_diff* diff); | ||
|
||
/// Goto next diff line on stc. If at end, goes to next stc. | ||
bool next(); | ||
|
||
/// Goto previous diff line on stc. If at begin, goes to previous stc. | ||
bool prev(); | ||
|
||
/// Returns number of differences present. | ||
int size() const { return m_lines.size(); } | ||
|
||
private: | ||
stc* m_stc{nullptr}; | ||
|
||
std::set<int> m_lines; | ||
std::set<int>::iterator m_lines_it; | ||
}; | ||
}; // namespace wex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Name: unified-diffs.cpp | ||
// Purpose: Implementation of class unified_diffs | ||
// Author: Anton van Wezenbeek | ||
// Copyright: (c) 2024 Anton van Wezenbeek | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include <wex/stc/stc.h> | ||
#include <wex/vcs/unified-diff.h> | ||
#include <wex/vcs/unified-diffs.h> | ||
|
||
wex::unified_diffs::unified_diffs(stc* s) | ||
: m_stc(s) | ||
, m_lines_it(m_lines.begin()) | ||
{ | ||
} | ||
|
||
void wex::unified_diffs::clear() | ||
{ | ||
m_lines.clear(); | ||
m_lines_it = m_lines.begin(); | ||
} | ||
|
||
int wex::unified_diffs::distance() const | ||
{ | ||
return std::distance(m_lines.begin(), m_lines_it); | ||
} | ||
|
||
bool wex::unified_diffs::first() | ||
{ | ||
if (m_lines.empty()) | ||
{ | ||
return false; | ||
} | ||
|
||
m_lines_it = m_lines.begin(); | ||
|
||
m_stc->goto_line(*m_lines_it); | ||
|
||
return true; | ||
} | ||
|
||
void wex::unified_diffs::insert(const unified_diff* diff) | ||
{ | ||
if (diff->range_from_start() != 0) | ||
{ | ||
m_lines.insert(diff->range_from_start() - 1); | ||
} | ||
|
||
if (diff->range_to_start() != 0) | ||
{ | ||
m_lines.insert(diff->range_to_start() - 1); | ||
} | ||
|
||
m_lines_it = m_lines.begin(); | ||
} | ||
|
||
bool wex::unified_diffs::next() | ||
{ | ||
if (m_lines_it == m_lines.end() || | ||
m_lines_it == std::prev(m_lines.end())) | ||
{ | ||
return m_stc->get_vi().command(":n"); | ||
} | ||
|
||
m_lines_it++; | ||
|
||
m_stc->goto_line(*m_lines_it); | ||
|
||
return true; | ||
} | ||
|
||
bool wex::unified_diffs::prev() | ||
{ | ||
if (m_lines_it == m_lines.begin()) | ||
{ | ||
return m_stc->get_vi().command(":prev"); | ||
} | ||
|
||
m_lines_it--; | ||
|
||
m_stc->goto_line(*m_lines_it); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.