mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 22:37:10 +09:00
Create empty file if input doesn't exist
This commit is contained in:
@@ -50,18 +50,23 @@ class Buffer {
|
||||
|
||||
void remove(ulong start, ulong end) {
|
||||
text.remove(start, end);
|
||||
update();
|
||||
}
|
||||
void insert(ulong position, string value) {
|
||||
text.insert(position, value);
|
||||
update();
|
||||
}
|
||||
string substring(ulong start, ulong end = -1) {
|
||||
if (end == -1) {
|
||||
update();
|
||||
return text.substring(start, text.length);
|
||||
} else {
|
||||
update();
|
||||
return text.substring(start, end);
|
||||
}
|
||||
}
|
||||
char charAt(ulong pos) {
|
||||
update();
|
||||
return text.charAt(pos);
|
||||
}
|
||||
}
|
||||
|
||||
16
src/main.d
16
src/main.d
@@ -12,12 +12,24 @@ void main(string[] args) {
|
||||
|
||||
if (args.length > 1) {
|
||||
filename = args[1];
|
||||
fileTxt = readText(filename);
|
||||
if (!exists(filename)) {
|
||||
File file = File(filename, "w");
|
||||
file.close();
|
||||
} else {
|
||||
if (isDir(filename)) {
|
||||
writeln(filename, " is a directory");
|
||||
return;
|
||||
}
|
||||
fileTxt = readText(filename);
|
||||
if (fileTxt is null) {
|
||||
fileTxt = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Buffer buf = new Buffer(fileTxt, filename);
|
||||
init();
|
||||
|
||||
Buffer buf = new Buffer(fileTxt, filename);
|
||||
Cursor cursor = new Cursor();
|
||||
View v = new View(buf, cursor);
|
||||
|
||||
|
||||
@@ -51,6 +51,9 @@ class Rope {
|
||||
void remove(ulong start, ulong end) {
|
||||
if (value !is null) {
|
||||
value = to!string(value.to!dstring[0 .. start] ~ value.to!dstring[end .. $]);
|
||||
if (value is null) {
|
||||
value = "";
|
||||
}
|
||||
length = value.count;
|
||||
} else {
|
||||
auto leftStart = min(start, left.length);
|
||||
|
||||
@@ -152,7 +152,6 @@ class View {
|
||||
if (cursor.y > topline + height-1) {
|
||||
topline = cursor.y - height-1;
|
||||
}
|
||||
buf.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user