mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-14 02:38:37 +12:00
Implement Caret upwards and downwards move in overlay_edit_text (#8342)
* Implement caret upwards and downwards move in overlay_edit_text * Optimize caret up and down movement Co-authored-by: Megamouse <studienricky89@googlemail.com>
This commit is contained in:
parent
6a9fe8e3c4
commit
eea12bad07
1 changed files with 61 additions and 2 deletions
|
@ -5,6 +5,30 @@ namespace rsx
|
|||
{
|
||||
namespace overlays
|
||||
{
|
||||
static size_t get_line_start(const std::u32string& text, size_t pos)
|
||||
{
|
||||
if (pos == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const size_t line_start = text.rfind('\n', pos - 1);
|
||||
if (line_start == std::string::npos)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return line_start + 1;
|
||||
}
|
||||
|
||||
static size_t get_line_end(const std::u32string& text, size_t pos)
|
||||
{
|
||||
const size_t line_end = text.find('\n', pos);
|
||||
if (line_end == std::string::npos)
|
||||
{
|
||||
return text.length();
|
||||
}
|
||||
return line_end;
|
||||
}
|
||||
|
||||
void edit_text::move_caret(direction dir)
|
||||
{
|
||||
switch (dir)
|
||||
|
@ -28,10 +52,45 @@ namespace rsx
|
|||
break;
|
||||
}
|
||||
case up:
|
||||
case down:
|
||||
// TODO
|
||||
{
|
||||
const size_t current_line_start = get_line_start(text, caret_position);
|
||||
if (current_line_start == 0)
|
||||
{
|
||||
// This is the first line, so caret moves to the very beginning
|
||||
caret_position = 0;
|
||||
refresh();
|
||||
break;
|
||||
}
|
||||
const size_t caret_pos_in_line = caret_position - current_line_start;
|
||||
const size_t prev_line_end = current_line_start - 1;
|
||||
const size_t prev_line_start = get_line_start(text, prev_line_end);
|
||||
// TODO : Save caret position to some kind of buffer, so after switching back and forward, caret would be on initial position
|
||||
caret_position = std::min(prev_line_end, prev_line_start + caret_pos_in_line);
|
||||
|
||||
refresh();
|
||||
break;
|
||||
}
|
||||
case down:
|
||||
{
|
||||
const size_t current_line_end = get_line_end(text, caret_position);
|
||||
if (current_line_end == text.length())
|
||||
{
|
||||
// This is the last line, so caret moves to the very end
|
||||
caret_position = current_line_end;
|
||||
refresh();
|
||||
break;
|
||||
}
|
||||
const size_t current_line_start = get_line_start(text, caret_position);
|
||||
const size_t caret_pos_in_line = caret_position - current_line_start;
|
||||
const size_t next_line_start = current_line_end + 1;
|
||||
const size_t next_line_end = get_line_end(text, next_line_start);
|
||||
// TODO : Save caret position to some kind of buffer, so after switching back and forward, caret would be on initial position
|
||||
caret_position = std::min(next_line_end, next_line_start + caret_pos_in_line);
|
||||
|
||||
refresh();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void edit_text::insert_text(const std::u32string& str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue