aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wiki.js18
1 files changed, 8 insertions, 10 deletions
diff --git a/wiki.js b/wiki.js
index d9061a0..1d47062 100644
--- a/wiki.js
+++ b/wiki.js
@@ -6,7 +6,7 @@ function insert(text) {
var end = t.selectionEnd;
t.value = t.value.substring(0, pos) + text + t.value.substring(end, t.value.length);
}
- t.focus(); // CONCENTRATE
+ t.focus();
var cpos = t.selectionStart;
t.setSelectionRange(cpos, cpos);
}
@@ -32,30 +32,28 @@ function prepend(text) {
if(t.selectionStart || t.selectionStart == '0') {
var pos = t.selectionStart;
var end = t.selectionEnd;
- for(;pos < end; pos++) { // let me see you strip
+ for(;pos < end; pos++) {
if(t.value.charAt(pos) != "\n") break;
}
- for(;end > pos; end--) { // front and back
+ for(;end > pos; end--) {
if(t.value.charAt(end - 1) != "\n") break;
}
var quote = "";
var cpos = end;
- if(t.value.charAt(pos - 1) != "\n") { // in the middle of something?
- quote += "\n"; // PRE-pend, dang it
+ if(t.value.charAt(pos - 1) != "\n") {
+ quote += "\n";
cpos += 1;
}
- if(pos == end) { // no selection. text only. final destination.
+ if(pos == end) {
quote += text;
cpos += text.length;
} else {
var lines = t.value.substring(pos, end).split("\n");
for(var i=0; i < lines.length; i++) {
- // do we want to prepend for empty lines inside selection?
- // if not, add check here. DECISIONS
quote += text + lines[i] + "\n";
- cpos += text.length; // should i add 1 here for the newline? who knows!
+ cpos += text.length;
}
- quote = quote.slice(0, -1); // strip bo(g|n)us newline
+ quote = quote.slice(0, -1);
}
t.value = t.value.substring(0, pos) + quote + t.value.substring(end, t.value.length);
}