mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-18 23:07:13 +09:00
Merge
This commit is contained in:
@@ -11,11 +11,11 @@ import (
|
||||
const (
|
||||
// Opposite and undoing events must have opposite values
|
||||
|
||||
// TextEventInsert repreasents an insertion event
|
||||
// TextEventInsert represents an insertion event
|
||||
TextEventInsert = 1
|
||||
// TextEventRemove represents a deletion event
|
||||
TextEventRemove = -1
|
||||
|
||||
// TextEventReplace represents a replace event
|
||||
TextEventReplace = 0
|
||||
)
|
||||
|
||||
@@ -117,7 +117,7 @@ func (eh *EventHandler) Remove(start, end Loc) {
|
||||
eh.Execute(e)
|
||||
}
|
||||
|
||||
// Multiple creates an multiple insertions executes them
|
||||
// MultipleReplace creates an multiple insertions executes them
|
||||
func (eh *EventHandler) MultipleReplace(deltas []Delta) {
|
||||
e := &TextEvent{
|
||||
C: eh.buf.Cursor,
|
||||
|
||||
@@ -267,11 +267,16 @@ func Abs(n int) int {
|
||||
return n
|
||||
}
|
||||
|
||||
// FuncName returns the name of a given function object
|
||||
// FuncName returns the full name of a given function object
|
||||
func FuncName(i interface{}) string {
|
||||
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
|
||||
}
|
||||
|
||||
// ShortFuncName returns the name only of a given function object
|
||||
func ShortFuncName(i interface{}) string {
|
||||
return strings.TrimPrefix(runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name(), "main.(*View).")
|
||||
}
|
||||
|
||||
// SplitCommandArgs separates multiple command arguments which may be quoted.
|
||||
// The returned slice contains at least one string
|
||||
func SplitCommandArgs(input string) []string {
|
||||
|
||||
@@ -462,6 +462,7 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
case *tcell.EventKey:
|
||||
// Check first if input is a key binding, if it is we 'eat' the input and don't insert a rune
|
||||
isBinding := false
|
||||
readonlyBindingsList := []string{"Delete", "Insert", "Backspace", "Cut", "Play", "Paste", "Move", "Add", "DuplicateLine", "Macro"}
|
||||
if e.Key() != tcell.KeyRune || e.Modifiers() != 0 {
|
||||
for key, actions := range bindings {
|
||||
if e.Key() == key.keyCode {
|
||||
@@ -474,11 +475,24 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
relocate = false
|
||||
isBinding = true
|
||||
for _, action := range actions {
|
||||
relocate = action(v, true) || relocate
|
||||
funcName := FuncName(action)
|
||||
if funcName != "main.(*View).ToggleMacro" && funcName != "main.(*View).PlayMacro" {
|
||||
if recordingMacro {
|
||||
curMacro = append(curMacro, action)
|
||||
readonlyBindingsResult := false
|
||||
funcName := ShortFuncName(action)
|
||||
if v.Type.readonly == true {
|
||||
// check for readonly and if true only let key bindings get called if they do not change the contents.
|
||||
for _, readonlyBindings := range readonlyBindingsList {
|
||||
if strings.Contains(funcName, readonlyBindings) {
|
||||
readonlyBindingsResult = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !readonlyBindingsResult {
|
||||
// call the key binding
|
||||
relocate = action(v, true) || relocate
|
||||
// Macro
|
||||
if funcName != "ToggleMacro" && funcName != "PlayMacro" {
|
||||
if recordingMacro {
|
||||
curMacro = append(curMacro, action)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,33 +502,39 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
}
|
||||
}
|
||||
if !isBinding && e.Key() == tcell.KeyRune {
|
||||
// Insert a character
|
||||
if v.Cursor.HasSelection() {
|
||||
v.Cursor.DeleteSelection()
|
||||
v.Cursor.ResetSelection()
|
||||
}
|
||||
v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
|
||||
v.Cursor.Right()
|
||||
|
||||
for pl := range loadedPlugins {
|
||||
_, err := Call(pl+".onRune", string(e.Rune()), v)
|
||||
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
|
||||
TermMessage(err)
|
||||
// Check viewtype if readonly don't insert a rune (readonly help and log view etc.)
|
||||
if v.Type.readonly == false {
|
||||
// Insert a character
|
||||
if v.Cursor.HasSelection() {
|
||||
v.Cursor.DeleteSelection()
|
||||
v.Cursor.ResetSelection()
|
||||
}
|
||||
}
|
||||
v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
|
||||
v.Cursor.Right()
|
||||
|
||||
if recordingMacro {
|
||||
curMacro = append(curMacro, e.Rune())
|
||||
for pl := range loadedPlugins {
|
||||
_, err := Call(pl+".onRune", string(e.Rune()), v)
|
||||
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
|
||||
TermMessage(err)
|
||||
}
|
||||
}
|
||||
|
||||
if recordingMacro {
|
||||
curMacro = append(curMacro, e.Rune())
|
||||
}
|
||||
}
|
||||
}
|
||||
case *tcell.EventPaste:
|
||||
if !PreActionCall("Paste", v) {
|
||||
break
|
||||
// Check viewtype if readonly don't paste (readonly help and log view etc.)
|
||||
if v.Type.readonly == false {
|
||||
if !PreActionCall("Paste", v) {
|
||||
break
|
||||
}
|
||||
|
||||
v.paste(e.Text())
|
||||
|
||||
PostActionCall("Paste", v)
|
||||
}
|
||||
|
||||
v.paste(e.Text())
|
||||
|
||||
PostActionCall("Paste", v)
|
||||
case *tcell.EventMouse:
|
||||
x, y := e.Position()
|
||||
x -= v.lineNumOffset - v.leftCol + v.x
|
||||
@@ -571,9 +591,12 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
}
|
||||
}
|
||||
case tcell.Button2:
|
||||
// Middle mouse button was clicked,
|
||||
// We should paste primary
|
||||
v.PastePrimary(true)
|
||||
// Check viewtype if readonly don't paste (readonly help and log view etc.)
|
||||
if v.Type.readonly == false {
|
||||
// Middle mouse button was clicked,
|
||||
// We should paste primary
|
||||
v.PastePrimary(true)
|
||||
}
|
||||
case tcell.ButtonNone:
|
||||
// Mouse event with no click
|
||||
if !v.mouseReleased {
|
||||
@@ -937,7 +960,7 @@ func (v *View) Display() {
|
||||
}
|
||||
v.DisplayView()
|
||||
// Don't draw the cursor if it is out of the viewport or if it has a selection
|
||||
if (v.Cursor.Y-v.Topline < 0 || v.Cursor.Y-v.Topline > v.Height-1) || (v.Cursor.HasSelection() && v.Num == tabs[curTab].CurView) {
|
||||
if v.Num == tabs[curTab].CurView && (v.Cursor.Y-v.Topline < 0 || v.Cursor.Y-v.Topline > v.Height-1 || v.Cursor.HasSelection()) {
|
||||
screen.HideCursor()
|
||||
}
|
||||
_, screenH := screen.Size()
|
||||
|
||||
27
com.github.zyedidia.micro.metainfo.xml
Normal file
27
com.github.zyedidia.micro.metainfo.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component>
|
||||
<id>com.github.zyedidia.micro</id>
|
||||
<name>Micro Text Editor</name>
|
||||
<summary>A modern and intuitive terminal-based text editor</summary>
|
||||
<url type="homepage">https://micro-editor.github.io</url>
|
||||
<url type="bugtracker">https://github.com/zyedidia/micro</url>
|
||||
<metadata_license>MIT</metadata_license>
|
||||
<categories>
|
||||
<category>Development</category>
|
||||
<category>TextEditor</category>
|
||||
</categories>
|
||||
|
||||
<provides>
|
||||
<binary>micro</binary>
|
||||
</provides>
|
||||
<releases>
|
||||
<release version="1.2.0" date="2017-05-28" />
|
||||
</releases>
|
||||
<developer_name>Zachary Yedidia</developer_name>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<caption>Micro Text Editor editing its source code.</caption>
|
||||
<image type="source">https://raw.githubusercontent.com/zyedidia/micro/master/assets/micro-solarized.png</image>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
</component>
|
||||
@@ -12,16 +12,17 @@ If you don't like it, you can change it!
|
||||
|
||||
#Power user
|
||||
+--------+---------------------------------------------------------+
|
||||
| Key | Description of function |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+E | Switch to the micro command prompt to run a command. |
|
||||
| | (See `>help commands` for a list of commands. ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Tab | In command prompt it will auto complete if possible. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+B | Run shell commands in micro's current working directory.|
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Navigation
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Key | Description of function |
|
||||
|--------+---------------------------------------------------------+
|
||||
| Arrows | Move the cursor around your current document. |
|
||||
| | (Yes this is rebindable to the vim keys if you want.) |
|
||||
@@ -29,19 +30,52 @@ If you don't like it, you can change it!
|
||||
| Shift+ | Move and select text. |
|
||||
| Arrows | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Home | Move to the beginning of the current line. (Naturally.) |
|
||||
| Home | |
|
||||
| or | |
|
||||
| Ctrl+ | Move to the beginning of the current line. (Naturally.) |
|
||||
| Left | |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| End | Move to the end of the current line. |
|
||||
| End | |
|
||||
| or | |
|
||||
| Ctrl+ | Move to the end of the current line. |
|
||||
| Right | |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+ | |
|
||||
| Left | Move cursor one complete word left. |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+ | |
|
||||
| Right | Move cursor one complete word right. |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| PageUp | Move cursor up lines quickly. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| PageDn | Move cursor down lines quickly. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+ | |
|
||||
| Home | |
|
||||
| or | Move cursor to start of the document |
|
||||
| Ctrl+ | |
|
||||
| Up | |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+ | |
|
||||
| End | |
|
||||
| or | Move cursor to end of the document |
|
||||
| Ctrl+ | |
|
||||
| Down | |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+L | Jump to line in current file. ( Prompts for line # ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+W | Move between splits open in current tab. |
|
||||
| | (See vsplit and hsplit in `>help commands`) |
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Tabs
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+T | Open a new tab. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+, | Move to the previous tab in the tablist. |
|
||||
@@ -51,7 +85,6 @@ If you don't like it, you can change it!
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Find Operations
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+F | Find text in current file. ( Prompts for text to find.) |
|
||||
+--------+---------------------------------------------------------+
|
||||
@@ -61,7 +94,6 @@ If you don't like it, you can change it!
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#File Operations
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+Q | Close current file. ( Quits micro if last file open. ) |
|
||||
+--------+---------------------------------------------------------+
|
||||
@@ -71,10 +103,45 @@ If you don't like it, you can change it!
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Text operations
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+A | Select all text in current file. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+ | |
|
||||
| Shift+ | Select complete word right. |
|
||||
| Right | |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+ | |
|
||||
| Shift+ | Select complete word left. |
|
||||
| Left | |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Shift+ | |
|
||||
| Home | |
|
||||
| or | Select from the current cursor position to the |
|
||||
| Ctrl+ | start of the current line. |
|
||||
| Shift+ | |
|
||||
| Left | |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Shift+ | |
|
||||
| End | |
|
||||
| or | Select from the current cursor position to the |
|
||||
| Ctrl+ | end of the current line. |
|
||||
| Shift+ | |
|
||||
| Right | |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+ | |
|
||||
| Shift+ | Select from the current cursor position to the |
|
||||
| Up | start of the document. |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+ | |
|
||||
| Shift+ | Select from the current cursor position to the |
|
||||
| Down | end of the document. |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+X | Cut selected text. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+C | Copy selected text. |
|
||||
@@ -89,6 +156,30 @@ If you don't like it, you can change it!
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+Y | Redo actions. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+ | |
|
||||
| Up | Move current line or selected lines up. |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+ | |
|
||||
| Down | Move current line or selected lines down. |
|
||||
| Arrow | |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+ | |
|
||||
| Ctrl+H | |
|
||||
| or | Delete complete word left. |
|
||||
| Alt+ | |
|
||||
| Back- | |
|
||||
| space | |
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Macros
|
||||
+--------+---------------------------------------------------------+
|
||||
| | Toggle ON/OFF macro recording. |
|
||||
| Ctrl+U | Simply press Ctrl+U to begin recording a macro and |
|
||||
| | press Ctrl+U to stop recording macro. |
|
||||
+--------+---------------------------------------------------------+
|
||||
| Ctrl+J | Run your recorded macro. |
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Other
|
||||
+--------+---------------------------------------------------------+
|
||||
@@ -101,7 +192,6 @@ If you don't like it, you can change it!
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Emacs style actions
|
||||
|
||||
+--------+---------------------------------------------------------+
|
||||
| Alt+F | Move to the end of the next word. (To the next space.) |
|
||||
+--------+---------------------------------------------------------+
|
||||
@@ -117,7 +207,6 @@ If you don't like it, you can change it!
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Function keys.
|
||||
|
||||
Warning! The function keys may not work in all terminals!
|
||||
+--------+---------------------------------------------------------+
|
||||
| F1 | Open help. |
|
||||
@@ -133,9 +222,3 @@ Warning! The function keys may not work in all terminals!
|
||||
| F10 | Close current file. |
|
||||
+--------+---------------------------------------------------------+
|
||||
|
||||
#Macros
|
||||
|
||||
Micro supports the use of keyboard macros. Simply press Ctrl+U to
|
||||
begin recording a macro and press Ctrl+U to stop recording.
|
||||
|
||||
Press Ctrl+J to run your recorded macro.
|
||||
Reference in New Issue
Block a user