-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
163 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#include <vtbackend/JumpHistory.h> | ||
|
||
namespace vtbackend | ||
{ | ||
|
||
CellLocation JumpHistory::jumpToLast(CellLocation current) | ||
{ | ||
applyOffset(); | ||
CellLocation last = _history.back(); | ||
if (last == current) | ||
{ | ||
_history.pop_back(); | ||
if (_history.empty()) | ||
{ | ||
return current; | ||
} | ||
last = _history.back(); | ||
} | ||
_history.pop_back(); | ||
_history.push_back(current); | ||
_current = _history.size(); | ||
return last; | ||
} | ||
|
||
CellLocation JumpHistory::jumpToMarkBackward([[maybe_unused]] CellLocation current) | ||
{ | ||
applyOffset(); | ||
if (_current == 0) | ||
{ | ||
// loop | ||
_current = _history.size() - 1; | ||
} | ||
else | ||
{ | ||
_current--; | ||
} | ||
return _history[_current]; | ||
} | ||
|
||
CellLocation JumpHistory::jumpToMarkForward([[maybe_unused]] CellLocation current) | ||
{ | ||
applyOffset(); | ||
if (_current == _history.size()) | ||
{ | ||
// loop | ||
_current = 0; | ||
} | ||
else | ||
{ | ||
_current++; | ||
} | ||
return _history[_current]; | ||
} | ||
|
||
} // namespace vtbackend |
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,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#pragma once | ||
|
||
#include <vtbackend/primitives.h> | ||
|
||
#include <vector> | ||
|
||
namespace vtbackend | ||
{ | ||
|
||
class JumpHistory | ||
{ | ||
|
||
public: | ||
template <typename T> | ||
void add(T&& cell) | ||
{ | ||
applyOffset(); | ||
_history.push_back(std::forward<T>(cell)); | ||
} | ||
CellLocation jumpToLast(CellLocation current); | ||
CellLocation jumpToMarkBackward(CellLocation current); | ||
CellLocation jumpToMarkForward(CellLocation current); | ||
void addOffset(LineOffset offset) { _offsetSinceLastJump += offset; } | ||
|
||
private: | ||
std::vector<CellLocation> _history; | ||
size_t _current = 0; | ||
LineOffset _offsetSinceLastJump { 0 }; | ||
void applyOffset() | ||
{ | ||
if (unbox(_offsetSinceLastJump) == 0) | ||
return; | ||
for (auto& cell: _history) | ||
{ | ||
// minus since we are going in the history | ||
cell.line -= _offsetSinceLastJump; | ||
} | ||
_offsetSinceLastJump = LineOffset { 0 }; | ||
} | ||
}; | ||
} // namespace vtbackend |
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
Oops, something went wrong.