mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-07 13:20:21 +09:00
Add "smartpaste" option; fixes #1156
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user