Browse Source

Improved extend selection for latex

merge-requests/427/merge
eidheim 8 months ago
parent
commit
659dc0d49a
  1. 19
      src/source.cpp
  2. 7
      src/source_base.cpp
  3. 1
      src/source_base.hpp
  4. 2
      src/source_spellcheck.cpp

19
src/source.cpp

@ -1328,7 +1328,7 @@ void Source::View::setup_format_style(bool is_generic_view) {
};
}
}
else if(language_id == "latex") {
else if(is_latex) {
static auto yapf = filesystem::find_executable("latexindent");
if(!yapf.empty()) {
format_style = [this](bool continue_without_style_file, bool ignore_selection) {
@ -1678,6 +1678,7 @@ void Source::View::extend_selection() {
int angle_count = 0;
int curly_count = 0;
auto start_comma_iter = get_buffer()->end();
auto start_dollar_iter = get_buffer()->end();
auto start_angle_iter = get_buffer()->end();
auto start_angle_reversed_iter = get_buffer()->end();
while(start.backward_char()) {
@ -1722,6 +1723,10 @@ void Source::View::extend_selection() {
para_count == 0 && square_count == 0 && curly_count == 0 &&
*start == ',' && is_code_iter(start))
start_comma_iter = start;
else if(!start_dollar_iter &&
para_count == 0 && square_count == 0 && curly_count == 0 &&
*start == '$' && is_code_iter(start))
start_dollar_iter = start;
else if(!start_sentence_iter &&
para_count == 0 && square_count == 0 && curly_count == 0 &&
*start == ';' && is_code_iter(start))
@ -1739,6 +1744,7 @@ void Source::View::extend_selection() {
angle_count = 0;
curly_count = 0;
auto end_comma_iter = get_buffer()->end();
auto end_dollar_iter = get_buffer()->end();
auto end_angle_iter = get_buffer()->end();
auto end_angle_reversed_iter = get_buffer()->end();
do {
@ -1780,6 +1786,10 @@ void Source::View::extend_selection() {
para_count == 0 && square_count == 0 && curly_count == 0 &&
*end == ',' && is_code_iter(end))
end_comma_iter = end;
else if(!end_dollar_iter &&
para_count == 0 && square_count == 0 && curly_count == 0 &&
*end == '$' && is_code_iter(end))
end_dollar_iter = end;
else if(!end_sentence_iter &&
para_count == 0 && square_count == 0 && curly_count == 0 &&
*end == ';' && is_code_iter(end))
@ -1951,6 +1961,11 @@ void Source::View::extend_selection() {
}
select_matching_brackets = true;
}
else if(is_latex && start_dollar_iter && start < start_dollar_iter && end_dollar_iter && end > end_dollar_iter) {
start = start_dollar_iter;
end = end_dollar_iter;
select_matching_brackets = true;
}
// Attempt to select a sentence, for instance: int a = 2;
if(!is_bracket_language) { // If for instance cmake, meson or python
@ -3727,7 +3742,7 @@ bool Source::View::on_key_press_event_smart_inserts(GdkEventKey *event) {
right = "*/";
}
// Insert $$ around selection
else if(event->keyval == GDK_KEY_dollar && language_id == "latex") {
else if(is_latex && event->keyval == GDK_KEY_dollar) {
left = '$';
right = '$';
}

7
src/source_base.cpp

@ -26,6 +26,8 @@ Source::CommonView::CommonView(const Glib::RefPtr<Gsv::Language> &language) : Gs
is_cpp = true;
else if(is_language({"js", "html"}))
is_js = true;
else if(is_language({"latex"}))
is_latex = true;
search_settings = gtk_source_search_settings_new();
gtk_source_search_settings_set_wrap_around(search_settings, true);
@ -891,9 +893,10 @@ bool Source::BaseView::is_whitespace_char(gunichar chr) {
}
bool Source::BaseView::is_token_char(gunichar chr) {
return (chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z') || (chr >= '0' && chr <= '9') || chr == '_' || chr == '$' || chr >= 128 ||
return (chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z') || (chr >= '0' && chr <= '9') || chr == '_' || (!is_latex && chr == '$') || chr >= 128 ||
(language_id == "css" && chr == '-') ||
(language_id == "rust" && chr == '!');
(language_id == "rust" && chr == '!') ||
(is_latex && chr == '\\');
}
std::pair<Gtk::TextIter, Gtk::TextIter> Source::BaseView::get_token_iters(Gtk::TextIter iter) {

1
src/source_base.hpp

@ -47,6 +47,7 @@ namespace Source {
bool is_cpp = false;
/// Set to true if language is html or js (including typescript)
bool is_js = false;
bool is_latex = false;
bool keep_clipboard = false;

2
src/source_spellcheck.cpp

@ -476,6 +476,8 @@ bool Source::SpellCheckView::is_code_iter(const Gtk::TextIter &iter) {
if(is_bracket_language)
return is_code_iter;
if(is_latex)
return true;
// Non-bracket languages can have code iters inside (), [] and {}, while non-code iters outside of these brackets
// Do not threat these closing code brackets as code iters

Loading…
Cancel
Save