| 898 | select(_cursor_pos, _cursor_pos); |
| 899 | } |
| 900 | void reshade::imgui::code_editor::insert_character(uint32_t c, bool auto_indent) |
| 901 | { |
| 902 | undo_record u; |
| 903 | |
| 904 | if (has_selection()) |
| 905 | { |
| 906 | if (c == '\t' && auto_indent) // Pressing tab with a selection indents the entire selection |
| 907 | { |
| 908 | text_pos &beg = _select_beg; |
| 909 | text_pos &end = _select_end; |
| 910 | |
| 911 | _colorize_line_beg = std::min(_colorize_line_beg, beg.line - std::min(beg.line, static_cast<size_t>(10))); |
| 912 | _colorize_line_end = std::max(_colorize_line_end, end.line + 10 + 1); |
| 913 | |
| 914 | beg.column = 0; |
| 915 | if (end.column == 0 && end.line > 0) |
| 916 | end.column = _lines[--end.line].size(); |
| 917 | |
| 918 | u.removed = get_text(beg, end); |
| 919 | u.removed_beg = beg; |
| 920 | u.removed_end = end; |
| 921 | |
| 922 | for (size_t i = beg.line; i <= end.line; i++) |
| 923 | { |
| 924 | std::vector<glyph> &line = _lines[i]; |
| 925 | |
| 926 | if (ImGui::GetIO().KeyShift) |
| 927 | { |
| 928 | if (line.empty()) |
| 929 | continue; // Line is already empty, so there is no indentation to remove |
| 930 | |
| 931 | if (line[0].c == '\t') |
| 932 | { |
| 933 | line.erase(line.begin()); |
| 934 | if (i == end.line && end.column > 0) |
| 935 | end.column--; |
| 936 | if (i == _cursor_pos.line && _cursor_pos.column > 0) |
| 937 | _cursor_pos.column--; |
| 938 | } |
| 939 | else for (size_t j = 0; j < _tab_size && !line.empty() && line[0].c == ' '; j++) // Do the same for spaces |
| 940 | { |
| 941 | line.erase(line.begin()); |
| 942 | if (i == end.line && end.column > 0) |
| 943 | end.column--; |
| 944 | if (i == _cursor_pos.line && _cursor_pos.column > 0) |
| 945 | _cursor_pos.column--; |
| 946 | } |
| 947 | } |
| 948 | else |
| 949 | { |
| 950 | line.insert(line.begin(), { '\t', color_background }); |
| 951 | if (i == end.line) |
| 952 | end.column++; |
| 953 | if (i == _cursor_pos.line) |
| 954 | _cursor_pos.column++; |
| 955 | } |
| 956 | } |
| 957 | |