mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 22:37:10 +09:00
Merge branch 'master' into view-refactor
This commit is contained in:
@@ -588,14 +588,20 @@ func (v *View) IndentSelection(usePlugin bool) bool {
|
||||
}
|
||||
|
||||
if v.Cursor.HasSelection() {
|
||||
startY := v.Cursor.CurSelection[0].Y
|
||||
endY := v.Cursor.CurSelection[1].Move(-1, v.Buf).Y
|
||||
endX := v.Cursor.CurSelection[1].Move(-1, v.Buf).X
|
||||
start := v.Cursor.CurSelection[0]
|
||||
end := v.Cursor.CurSelection[1]
|
||||
if end.Y < start.Y {
|
||||
start, end = end, start
|
||||
}
|
||||
|
||||
startY := start.Y
|
||||
endY := end.Move(-1, v.Buf).Y
|
||||
endX := end.Move(-1, v.Buf).X
|
||||
for y := startY; y <= endY; y++ {
|
||||
tabsize := len(v.Buf.IndentString())
|
||||
v.Buf.Insert(Loc{0, y}, v.Buf.IndentString())
|
||||
if y == startY && v.Cursor.CurSelection[0].X > 0 {
|
||||
v.Cursor.SetSelectionStart(v.Cursor.CurSelection[0].Move(tabsize, v.Buf))
|
||||
if y == startY && start.X > 0 {
|
||||
v.Cursor.SetSelectionStart(start.Move(tabsize, v.Buf))
|
||||
}
|
||||
if y == endY {
|
||||
v.Cursor.SetSelectionEnd(Loc{endX + tabsize + 1, endY})
|
||||
@@ -643,17 +649,23 @@ func (v *View) OutdentSelection(usePlugin bool) bool {
|
||||
}
|
||||
|
||||
if v.Cursor.HasSelection() {
|
||||
startY := v.Cursor.CurSelection[0].Y
|
||||
endY := v.Cursor.CurSelection[1].Move(-1, v.Buf).Y
|
||||
endX := v.Cursor.CurSelection[1].Move(-1, v.Buf).X
|
||||
start := v.Cursor.CurSelection[0]
|
||||
end := v.Cursor.CurSelection[1]
|
||||
if end.Y < start.Y {
|
||||
start, end = end, start
|
||||
}
|
||||
|
||||
startY := start.Y
|
||||
endY := end.Move(-1, v.Buf).Y
|
||||
endX := end.Move(-1, v.Buf).X
|
||||
for y := startY; y <= endY; y++ {
|
||||
for x := 0; x < len(v.Buf.IndentString()); x++ {
|
||||
if len(GetLeadingWhitespace(v.Buf.Line(y))) == 0 {
|
||||
break
|
||||
}
|
||||
v.Buf.Remove(Loc{0, y}, Loc{1, y})
|
||||
if y == startY && v.Cursor.CurSelection[0].X > 0 {
|
||||
v.Cursor.SetSelectionStart(v.Cursor.CurSelection[0].Move(-1, v.Buf))
|
||||
if y == startY && start.X > 0 {
|
||||
v.Cursor.SetSelectionStart(start.Move(-1, v.Buf))
|
||||
}
|
||||
if y == endY {
|
||||
v.Cursor.SetSelectionEnd(Loc{endX - x, endY})
|
||||
@@ -779,7 +791,7 @@ func (v *View) FindNext(usePlugin bool) bool {
|
||||
|
||||
if v.Cursor.HasSelection() {
|
||||
searchStart = ToCharPos(v.Cursor.CurSelection[1], v.Buf)
|
||||
lastSearch = v.Cursor.GetSelection()
|
||||
// lastSearch = v.Cursor.GetSelection()
|
||||
} else {
|
||||
searchStart = ToCharPos(v.Cursor.Loc, v.Buf)
|
||||
}
|
||||
|
||||
@@ -414,8 +414,8 @@ func DefaultBindings() map[string]string {
|
||||
"CtrlV": "Paste",
|
||||
"CtrlA": "SelectAll",
|
||||
"CtrlT": "AddTab",
|
||||
"CtrlRightSq": "PreviousTab",
|
||||
"CtrlBackslash": "NextTab",
|
||||
"Alt,": "PreviousTab",
|
||||
"Alt.": "NextTab",
|
||||
"Home": "StartOfLine",
|
||||
"End": "EndOfLine",
|
||||
"CtrlHome": "CursorStart",
|
||||
@@ -444,6 +444,7 @@ func DefaultBindings() map[string]string {
|
||||
// Integration with file managers
|
||||
"F1": "ToggleHelp",
|
||||
"F2": "Save",
|
||||
"F3": "Find",
|
||||
"F4": "Quit",
|
||||
"F7": "Find",
|
||||
"F10": "Quit",
|
||||
|
||||
@@ -326,6 +326,13 @@ func VSplit(args []string) {
|
||||
home, _ := homedir.Dir()
|
||||
filename = strings.Replace(filename, "~", home, 1)
|
||||
file, err := os.Open(filename)
|
||||
fileInfo, _ := os.Stat(filename)
|
||||
|
||||
if err == nil && fileInfo.IsDir() {
|
||||
messenger.Error(filename, " is a directory")
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
var buf *Buffer
|
||||
@@ -349,6 +356,13 @@ func HSplit(args []string) {
|
||||
home, _ := homedir.Dir()
|
||||
filename = strings.Replace(filename, "~", home, 1)
|
||||
file, err := os.Open(filename)
|
||||
fileInfo, _ := os.Stat(filename)
|
||||
|
||||
if err == nil && fileInfo.IsDir() {
|
||||
messenger.Error(filename, " is a directory")
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
var buf *Buffer
|
||||
@@ -382,10 +396,24 @@ func NewTab(args []string) {
|
||||
filename := args[0]
|
||||
home, _ := homedir.Dir()
|
||||
filename = strings.Replace(filename, "~", home, 1)
|
||||
file, _ := os.Open(filename)
|
||||
file, err := os.Open(filename)
|
||||
fileInfo, _ := os.Stat(filename)
|
||||
|
||||
if err == nil && fileInfo.IsDir() {
|
||||
messenger.Error(filename, " is a directory")
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
tab := NewTabFromView(NewView(NewBuffer(file, filename)))
|
||||
var buf *Buffer
|
||||
if err != nil {
|
||||
buf = NewBuffer(strings.NewReader(""), filename)
|
||||
} else {
|
||||
buf = NewBuffer(file, filename)
|
||||
}
|
||||
|
||||
tab := NewTabFromView(NewView(buf))
|
||||
tab.SetNum(len(tabs))
|
||||
tabs = append(tabs, tab)
|
||||
curTab = len(tabs) - 1
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -244,6 +244,13 @@ func (v *View) Open(filename string) {
|
||||
home, _ := homedir.Dir()
|
||||
filename = strings.Replace(filename, "~", home, 1)
|
||||
file, err := os.Open(filename)
|
||||
fileInfo, _ := os.Stat(filename)
|
||||
|
||||
if err == nil && fileInfo.IsDir() {
|
||||
messenger.Error(filename, " is a directory")
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
var buf *Buffer
|
||||
@@ -718,12 +725,6 @@ func (v *View) DisplayView() {
|
||||
|
||||
screenX = v.x
|
||||
|
||||
if v.x != 0 {
|
||||
// Draw the split divider
|
||||
screen.SetContent(screenX, yOffset+visualLineN, '|', nil, defStyle.Reverse(true))
|
||||
screenX++
|
||||
}
|
||||
|
||||
// If there are gutter messages we need to display the '>>' symbol here
|
||||
if hasGutterMessages {
|
||||
// msgOnLine stores whether or not there is a gutter message on this line in particular
|
||||
@@ -891,8 +892,12 @@ func (v *View) DisplayView() {
|
||||
}
|
||||
|
||||
if v.x != 0 && visualLineN < v.Height {
|
||||
dividerStyle := defStyle
|
||||
if style, ok := colorscheme["divider"]; ok {
|
||||
dividerStyle = style
|
||||
}
|
||||
for i := visualLineN + 1; i < v.Height; i++ {
|
||||
screen.SetContent(v.x, yOffset+i, '|', nil, defStyle.Reverse(true))
|
||||
screen.SetContent(v.x, yOffset+i, '|', nil, dividerStyle.Reverse(true))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user