Rework tabs, so they are a grid, not just n spaces
This commit is contained in:
parent
69f45fe50c
commit
f8e0a06a62
3 changed files with 8 additions and 6 deletions
|
@ -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:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#define TAB_SIZE 2
|
||||
#define TAB_SIZE 8
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
|
10
treap.cpp
10
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<string> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue