summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-01-12 21:13:44 +0100
committertomsmeding <tom.smeding@gmail.com>2017-01-12 22:09:47 +0100
commit790a796de93c6f9868ce78f4aea9262461e2b8c9 (patch)
tree86baf48ec97c513a68746d66a5ba35059bc877c5
parent2275e9ab7cb53dbb40887028544e80dd39597402 (diff)
Buffer dirty marking
-rw-r--r--buffer.cpp10
-rw-r--r--buffer.h2
-rw-r--r--manager.cpp3
3 files changed, 14 insertions, 1 deletions
diff --git a/buffer.cpp b/buffer.cpp
index 1366862..b185b99 100644
--- a/buffer.cpp
+++ b/buffer.cpp
@@ -34,6 +34,7 @@ void Buffer::handleCommand(const Command &cmd){
cursor.line=0;
cursor.x=0;
screen.clear();
+ dirty=false;
manager->receive({"info","Opened, read "+to_string(nread)+" characters"});
} else if(cmd[0]=="save_file"){
if(filename.size()==0){
@@ -46,11 +47,13 @@ void Buffer::handleCommand(const Command &cmd){
return;
}
i64 nwritten=tb.write(file);
+ dirty=false;
manager->receive({"info","Saved, written "+to_string(nwritten)+" characters"});
} else if(cmd[0]=="insert_char"){
char c=cmd[1][0];
assert(c!='\n');
tb.insert(cursor.line,cursor.x,cmd[1][0]);
+ dirty=true;
cursor.x++;
relayoutScreen();
if(findCursorInScreen().x==-1){
@@ -59,6 +62,7 @@ void Buffer::handleCommand(const Command &cmd){
}
} else if(cmd[0]=="insert_newline"){
tb.insert(cursor.line,cursor.x,'\n');
+ dirty=true;
cursor.x=0;
cursor.line++;
relayoutScreen();
@@ -79,6 +83,7 @@ void Buffer::handleCommand(const Command &cmd){
cursor.x=tb.lineLen(cursor.line);
tb.erase(cursor.line,cursor.x);
}
+ dirty=true;
relayoutScreen();
if(findCursorInScreen().x==-1){
scrollUp();
@@ -91,6 +96,7 @@ void Buffer::handleCommand(const Command &cmd){
return;
}
tb.erase(cursor.line,cursor.x);
+ dirty=true;
relayoutScreen();
} else if(cmd[0]=="move_forward"){
if(cursor.line==tb.numLines()-1&&cursor.x==tb.lineLen(cursor.line)){
@@ -476,3 +482,7 @@ string Buffer::getText() const {
return tb.fullText();
}
}
+
+bool Buffer::isDirty() const {
+ return dirty;
+}
diff --git a/buffer.h b/buffer.h
index 119097e..b20c885 100644
--- a/buffer.h
+++ b/buffer.h
@@ -36,6 +36,7 @@ class Buffer{
const bool singleLineMode=false;
TextBlob tb;
+ bool dirty=false;
vector<ScreenLine> screen;
i64 lastWidth=-1,lastHeight=-1; //excluding the gutter
@@ -62,4 +63,5 @@ public:
void show(i64 atx,i64 aty,i64 width,i64 height);
string getText() const;
+ bool isDirty() const;
};
diff --git a/manager.cpp b/manager.cpp
index af8844c..a3e9738 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -59,7 +59,7 @@ void Manager::show(){
string bartext;
i64 hilight_start=-1,hilight_len;
for(size_t i=0;i<buffers.size();i++){
- const string &fname=buffers[i].filename.size()==0?"<New file>":buffers[i].filename;
+ string fname=buffers[i].filename.size()==0?"<New file>":buffers[i].filename;
string tabtext=" ";
for(size_t j=0;j<fname.size();j++){
if(fname[j]=='/'){
@@ -82,6 +82,7 @@ void Manager::show(){
//+1 because the first char was already appended
tabtext+=fname.substr(nameidx+1,string::npos);
+ if(buffers[i].isDirty())tabtext+='*';
tabtext+=' ';
if((i64)i==activeIdx){