feat: fix add comment error on replace mode.

master
DebuggerX 4 years ago
parent 382803ac48
commit 56d7dd7050

@ -79,6 +79,7 @@ void walkPath(FileSystemEntity path) {
file = File(path.path); file = File(path.path);
sb.clear(); sb.clear();
modified = false; modified = false;
state = STATE.none;
if (isReplace) { if (isReplace) {
currentLineIndex = 0; currentLineIndex = 0;
operations.clear(); operations.clear();
@ -170,24 +171,20 @@ void walkPath(FileSystemEntity path) {
}); });
if (modified) { if (modified) {
if (isReplace) { if (isReplace) {
operations.forEach((ele) {
print('${ele.lineNumber} : ${ele.commented}');
});
operations.forEach((operation) { operations.forEach((operation) {
if (operation.commented && if (operation.commented &&
!lines[operation.lineNumber - 1].startsWith(_commentReg) && !lines[operation.lineNumber - 1].startsWith(_commentReg) &&
lines[operation.lineNumber - 1].trim().length > 0) lines[operation.lineNumber - 1].trim().length > 0) {
lines[operation.lineNumber - 1] = lines[operation.lineNumber - 1] =
'${' ' * operation.indent}// ${lines[operation.lineNumber - 1].substring(operation.indent)}'; '${' ' * operation.indent}// ${lines[operation.lineNumber - 1].substring(operation.indent)}';
else if (!operation.commented && } else if (!operation.commented &&
lines[operation.lineNumber - 1].startsWith(_commentReg)) lines[operation.lineNumber - 1].startsWith(_commentReg))
lines[operation.lineNumber - 1] = lines[operation.lineNumber - 1] =
lines[operation.lineNumber - 1].replaceFirst('// ', ''); lines[operation.lineNumber - 1].replaceFirst('// ', '');
}); });
print(lines.join('\n'));
file!.deleteSync(); file!.deleteSync();
File(path.path).writeAsStringSync(lines.join('\n'), flush: true); File(path.path).writeAsStringSync(lines.join('\n'), flush: true);
print("${file!.path} modified");
} else { } else {
file!.renameSync(path.path + '.bak'); file!.renameSync(path.path + '.bak');
File(path.path).writeAsStringSync(sb.toString(), flush: true); File(path.path).writeAsStringSync(sb.toString(), flush: true);

Loading…
Cancel
Save