@@ -655,11 +655,17 @@ export class PasteOperation {
655655
656656 public static getEdits ( config : CursorConfiguration , model : ICursorSimpleModel , selections : Selection [ ] , text : string , pasteOnNewLine : boolean [ ] | null , multicursorText : string [ ] ) {
657657 const distributedPaste = this . _distributePasteToCursors ( config , selections , text , pasteOnNewLine , multicursorText ) ;
658+ const [ singleIncludeNewline , multipleIncludeNewline ] = {
659+ 'always' : [ true , true ] ,
660+ 'never' : [ false , false ] ,
661+ 'singleOnly' : [ true , false ] ,
662+ 'multipleOnly' : [ false , true ]
663+ } [ config . pasteEmptySelectionIncludesNewline ] ;
658664 if ( distributedPaste ) {
659665 selections . sort ( Range . compareRangesUsingStarts ) ;
660- return this . _distributedPaste ( config , model , selections , distributedPaste , pasteOnNewLine ) ;
666+ return this . _distributedPaste ( config , model , selections , distributedPaste , pasteOnNewLine , multipleIncludeNewline ) ;
661667 } else {
662- return this . _simplePaste ( config , model , selections , text , pasteOnNewLine ) ;
668+ return this . _simplePaste ( config , model , selections , text , pasteOnNewLine , singleIncludeNewline ) ;
663669 }
664670 }
665671
@@ -688,15 +694,21 @@ export class PasteOperation {
688694 return null ;
689695 }
690696
691- private static _distributedPaste ( config : CursorConfiguration , model : ICursorSimpleModel , selections : Selection [ ] , texts : string [ ] , pasteOnNewLine : boolean [ ] | null ) : EditOperationResult {
697+ private static _distributedPaste ( config : CursorConfiguration , model : ICursorSimpleModel , selections : Selection [ ] , texts : string [ ] , pasteOnNewLine : boolean [ ] | null , includeNewline : boolean ) : EditOperationResult {
692698 if ( ! pasteOnNewLine ) {
693699 pasteOnNewLine = [ ] ;
694700 }
695701 const commands : ICommand [ ] = [ ] ;
696702 for ( let i = 0 , len = selections . length ; i < len ; i ++ ) {
697703 const selection = selections [ i ] ;
698- const text = texts [ i ] ;
704+ let text = texts [ i ] ;
699705 const position = selection . getPosition ( ) ;
706+ if ( ! includeNewline ) {
707+ text = text . slice ( 0 , text . length - 1 ) ;
708+ if ( text [ text . length - 1 ] === '\r' ) {
709+ text = text . slice ( 0 , text . length - 1 ) ;
710+ }
711+ }
700712 if ( pasteOnNewLine [ i ] && selection . isEmpty ( ) && text . indexOf ( '\n' ) === text . length - 1 ) {
701713 // Paste entire line at the beginning of line
702714 const typeSelection = new Range ( position . lineNumber , 1 , position . lineNumber , 1 ) ;
@@ -713,10 +725,16 @@ export class PasteOperation {
713725 } ) ;
714726 }
715727
716- private static _simplePaste ( config : CursorConfiguration , model : ICursorSimpleModel , selections : Selection [ ] , text : string , pasteOnNewLine : boolean [ ] | null ) : EditOperationResult {
728+ private static _simplePaste ( config : CursorConfiguration , model : ICursorSimpleModel , selections : Selection [ ] , text : string , pasteOnNewLine : boolean [ ] | null , includeNewline : boolean ) : EditOperationResult {
717729 const commands : ICommand [ ] = [ ] ;
718730 const singleCopyPasteOnNewLine = pasteOnNewLine ?. length === 1 && pasteOnNewLine [ 0 ] ;
719731 if ( ! pasteOnNewLine ) { pasteOnNewLine = [ ] ; }
732+ if ( ! includeNewline && text [ text . length - 1 ] === '\n' ) {
733+ text = text . slice ( 0 , text . length - 1 ) ;
734+ if ( text [ text . length - 1 ] === '\r' ) {
735+ text = text . slice ( 0 , text . length - 1 ) ;
736+ }
737+ }
720738 for ( let i = 0 , len = selections . length ; i < len ; i ++ ) {
721739 const selection = selections [ i ] ;
722740 const position = selection . getPosition ( ) ;
0 commit comments