forked from Botanical/BotanJS
		
	Handle the DELETE / BACKSPACE on INSERT
This commit is contained in:
		| @@ -14,6 +14,8 @@ | |||||||
| 		{ | 		{ | ||||||
| 			case "Tab": | 			case "Tab": | ||||||
| 				return "\t"; | 				return "\t"; | ||||||
|  | 			case "Enter": | ||||||
|  | 				return "\n"; | ||||||
| 			default: | 			default: | ||||||
| 				return c; | 				return c; | ||||||
| 		} | 		} | ||||||
| @@ -106,6 +108,11 @@ | |||||||
| 			this.__startPosition = ContentPosition( this.__cursor.feeder ); | 			this.__startPosition = ContentPosition( this.__cursor.feeder ); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		if( c == "\n" ) | ||||||
|  | 		{ | ||||||
|  | 			// todo | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		this.__insertLength += c.length; | 		this.__insertLength += c.length; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| @@ -117,9 +124,10 @@ | |||||||
| 		switch( e.keyCode ) | 		switch( e.keyCode ) | ||||||
| 		{ | 		{ | ||||||
| 			case 8: // Backspace | 			case 8: // Backspace | ||||||
| 				if( cur.X == 0 ) return; | 				var oY = feeder.panY + cur.Y; | ||||||
|  | 				if( cur.X == 0 && feeder.panY == 0 && cur.Y == 0 ) return; | ||||||
|  |  | ||||||
| 				cur.moveX( -1 ); | 				cur.moveX( -1, true, true ); | ||||||
|  |  | ||||||
| 				var f = ContentPosition( feeder ); | 				var f = ContentPosition( feeder ); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -54,6 +54,7 @@ | |||||||
| 		{ | 		{ | ||||||
| 			// Cursor movements | 			// Cursor movements | ||||||
| 			case BACKSPACE: // Backspace, go back 1 char, regardless of line | 			case BACKSPACE: // Backspace, go back 1 char, regardless of line | ||||||
|  | 				cfeeder.cursor.moveX( -1, true ); | ||||||
| 				break; | 				break; | ||||||
| 			case H: // Left | 			case H: // Left | ||||||
| 				cfeeder.cursor.moveX( -1 ); | 				cfeeder.cursor.moveX( -1 ); | ||||||
| @@ -70,7 +71,7 @@ | |||||||
|  |  | ||||||
| 			// Insert | 			// Insert | ||||||
| 			case A: // Append | 			case A: // Append | ||||||
| 				cfeeder.cursor.moveX( 1 ); | 				cfeeder.cursor.moveX( 1, true, true ); | ||||||
| 				cfeeder.cursor.openAction( "INSERT" ); | 				cfeeder.cursor.openAction( "INSERT" ); | ||||||
| 				break; | 				break; | ||||||
| 			case I: // Insert | 			case I: // Insert | ||||||
|   | |||||||
| @@ -82,7 +82,7 @@ | |||||||
|  |  | ||||||
| 	// Can only be 1, -1 | 	// Can only be 1, -1 | ||||||
| 	// 0 will be treated as undefined | 	// 0 will be treated as undefined | ||||||
| 	Cursor.prototype.moveX = function( d ) | 	Cursor.prototype.moveX = function( d, penentrate, phantomSpace ) | ||||||
| 	{ | 	{ | ||||||
| 		var x = this.pX; | 		var x = this.pX; | ||||||
|  |  | ||||||
| @@ -93,15 +93,29 @@ | |||||||
|  |  | ||||||
| 		var buffs = this.feeder.lineBuffers; | 		var buffs = this.feeder.lineBuffers; | ||||||
|  |  | ||||||
|  | 		if( penentrate && x < 0 && ( 0 < this.feeder.panY || 0 < this.Y ) ) | ||||||
|  | 		{ | ||||||
|  | 			this.moveY( -1 ); | ||||||
|  | 			this.lineEnd( phantomSpace ); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		/** @type {Components.Vim.LineBuffer} */ | 		/** @type {Components.Vim.LineBuffer} */ | ||||||
| 		var line = GetLine( buffs, this.Y ); | 		var line = GetLine( buffs, this.Y ); | ||||||
| 		var content = line.visualLines.join( "\n" ); | 		var content = line.visualLines.join( "\n" ); | ||||||
|  | 		var cLen = content.length; | ||||||
|  |  | ||||||
| 		var c = content[ x ]; | 		var c = content[ x ]; | ||||||
|  |  | ||||||
| 		if( c == undefined ) | 		// Include empty lines befor cursor end | ||||||
|  | 		if( ( phantomSpace && cLen - 1 <= x ) || ( cLen == 1 && c == undefined ) ) | ||||||
| 		{ | 		{ | ||||||
| 			x = d > 0 ? content.length - 1 : 0; | 			x = d > 0 ? cLen - 1 : 0; | ||||||
|  | 		} | ||||||
|  | 		// ( 2 < cLen ) Exclude empty lines at cursor end | ||||||
|  | 		else if( ( 2 < cLen && x == cLen - 1 && c == " " ) || c == undefined ) | ||||||
|  | 		{ | ||||||
|  | 			x = d > 0 ? cLen - 2 : 0; | ||||||
| 		} | 		} | ||||||
| 		else if( c == "\n" ) | 		else if( c == "\n" ) | ||||||
| 		{ | 		{ | ||||||
| @@ -124,9 +138,9 @@ | |||||||
| 		this.updatePosition(); | 		this.updatePosition(); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	Cursor.prototype.lineEnd = function() | 	Cursor.prototype.lineEnd = function( phantomSpace ) | ||||||
| 	{ | 	{ | ||||||
| 		this.moveX( Number.MAX_VALUE ); | 		this.moveX( Number.MAX_VALUE, false, phantomSpace ); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	Cursor.prototype.updatePosition = function() | 	Cursor.prototype.updatePosition = function() | ||||||
|   | |||||||
| @@ -97,6 +97,11 @@ | |||||||
|  |  | ||||||
| 	LineBuffer.prototype.toString = function() | 	LineBuffer.prototype.toString = function() | ||||||
| 	{ | 	{ | ||||||
|  | 		if( this.content.length < this.cols ) | ||||||
|  | 		{ | ||||||
|  | 			return this.content + " "; | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		return this.content || " "; | 		return this.content || " "; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user