diff --git a/editor.cpp b/editor.cpp index 1c60a39..112519a 100644 --- a/editor.cpp +++ b/editor.cpp @@ -257,7 +257,7 @@ bool Editor::take_action() { break; case '\t': file.insert(cur + file_offset, "\t"); - cur.c += TAB_SIZE; + cur.c += (cur.c - 1) % TAB_SIZE + 1; print_line(file_offset + cur.r); break; default: diff --git a/everything.hpp b/everything.hpp index 2af5abf..70d7ec2 100644 --- a/everything.hpp +++ b/everything.hpp @@ -5,7 +5,7 @@ #include #include -#define TAB_SIZE 2 +#define TAB_SIZE 8 using std::string; using std::vector; diff --git a/treap.cpp b/treap.cpp index fd14971..705bf1c 100644 --- a/treap.cpp +++ b/treap.cpp @@ -9,9 +9,11 @@ count_type Treap::get_size(line* l) { string Treap::substitute_tabs(string s) { string ret = ""; for(count_type i = 0; i < s.size(); ++i) { - if(s[i] == '\t') - for(int j = 0; j < TAB_SIZE; j++) + if(s[i] == '\t') { + ret += ' '; + while(ret.size() % TAB_SIZE != 0) ret += ' '; + } else ret += s[i]; } @@ -145,13 +147,13 @@ vector Treap::bulk_get_line(count_type r, count_type count) { return ret; } -// TODO tabs are a grid, not just N tabs +// Get how much tabs changed position on a row count_type Treap::get_tab_offset(position p) { count_type tab_offset = 0; string line = get_line(p.r, false); for(count_type i = 0; i + tab_offset < p.c; ++i) { if(line[i] == '\t') - tab_offset += TAB_SIZE - 1; + tab_offset += ((i+tab_offset-1) % TAB_SIZE); if(i + tab_offset > p.c) tab_offset -= i + tab_offset - p.c; }