Skip to content

Commit

Permalink
normalizeLine for input to '\n'
Browse files Browse the repository at this point in the history
fix issue jbt#19 for windows(\r\n)/mac(\r)
  • Loading branch information
yyjdelete committed Apr 17, 2016
1 parent 4812667 commit a5194dc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mdedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ function spliceString(str, i, remove, add){
return str.slice(0,i) + add + str.slice(i+remove);
}


function normalizeLine(str){
return str.replace(/\r(\n)?/g, '\n');
}

var actions = {
'newline': function(state, options){
var s = state.start;
Expand Down Expand Up @@ -855,6 +860,7 @@ Editor.prototype.getText = function(){
};

Editor.prototype.setText = function(val){
val = normalizeLine(val);
this.inner.textContent = val;
};

Expand Down Expand Up @@ -1085,6 +1091,7 @@ Editor.prototype.paste = function(evt){
evt.preventDefault();

var pasted = evt.clipboardData.getData('text/plain');
pasted = normalizeLine(pasted);

this.apply({
add: pasted,
Expand Down

0 comments on commit a5194dc

Please sign in to comment.