Add "smartpaste" option; fixes #1156

This commit is contained in:
supbish
2018-08-17 22:37:19 -04:00
parent 44e417c2f4
commit 905e984f29
3 changed files with 14 additions and 4 deletions

View File

@@ -231,6 +231,7 @@ func DefaultGlobalSettings() map[string]interface{} {
"scrollmargin": float64(3),
"scrollspeed": float64(2),
"softwrap": false,
"smartpaste": true,
"splitbottom": true,
"splitright": true,
"statusline": true,
@@ -271,6 +272,7 @@ func DefaultLocalSettings() map[string]interface{} {
"scrollmargin": float64(3),
"scrollspeed": float64(2),
"softwrap": false,
"smartpaste": true,
"splitbottom": true,
"splitright": true,
"statusline": true,

View File

@@ -198,16 +198,18 @@ func (v *View) ToggleTabbar() {
}
func (v *View) paste(clip string) {
leadingWS := ""
if v.Cursor.X > 0 {
leadingWS = GetLeadingWhitespace(v.Buf.Line(v.Cursor.Y))
if v.Buf.Settings["smartpaste"].(bool) {
if v.Cursor.X > 0 && GetLeadingWhitespace(strings.TrimLeft(clip, "\r\n")) == "" {
leadingWS := GetLeadingWhitespace(v.Buf.Line(v.Cursor.Y))
clip = strings.Replace(clip, "\n", "\n"+leadingWS, -1)
}
}
if v.Cursor.HasSelection() {
v.Cursor.DeleteSelection()
v.Cursor.ResetSelection()
}
clip = strings.Replace(clip, "\n", "\n"+leadingWS, -1)
v.Buf.Insert(v.Cursor.Loc, clip)
// v.Cursor.Loc = v.Cursor.Loc.Move(Count(clip), v.Buf)
v.freshClip = false

View File

@@ -164,6 +164,12 @@ Here are the options that you can set:
default value: `2`
* `smartpaste`: should micro add leading whitespace when pasting multiple lines?
This will attempt to preserve the current indentation level when pasting an
unindented block.
default value: `true`
* `softwrap`: should micro wrap lines that are too long to fit on the screen.
default value: `false`