Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/workspace #79

Merged
merged 4 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions editor/cmdline.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type CmdContent struct {

// Cmdline is the cmdline
type Cmdline struct {
ws *Workspace
pos int
content *CmdContent
preContent *CmdContent
Expand Down Expand Up @@ -64,7 +65,7 @@ func (c *Cmdline) show(args []interface{}) {
c.content.indent = indent
c.content.prompt = prompt
text := c.getText("")
palette := editor.palette
palette := c.ws.palette
palette.setPattern(text)
c.cursorMove()
if !c.wildmenuShown {
Expand All @@ -76,7 +77,7 @@ func (c *Cmdline) show(args []interface{}) {

func (c *Cmdline) showAddition() {
lines := append(c.getPromptLines(), c.getFunctionLines()...)
palette := editor.palette
palette := c.ws.palette
for i, resultItem := range palette.resultItems {
if i >= len(lines) || i >= palette.showTotal {
resultItem.hide()
Expand Down Expand Up @@ -117,11 +118,11 @@ func (c *Cmdline) getFunctionLines() []string {
}

func (c *Cmdline) cursorMove() {
editor.palette.cursorMove(c.pos + len(c.content.firstc) + c.content.indent)
c.ws.palette.cursorMove(c.pos + len(c.content.firstc) + c.content.indent)
}

func (c *Cmdline) hide(args []interface{}) {
palette := editor.palette
palette := c.ws.palette
palette.hide()
if c.inFunction {
c.function = append(c.function, c.content)
Expand Down Expand Up @@ -155,15 +156,15 @@ func (c *Cmdline) putChar(args []interface{}) {
// level := reflectToInt(args[2])
// fmt.Println("putChar", ch, shift, level)
text := c.getText(ch)
palette := editor.palette
palette := c.ws.palette
palette.setPattern(text)
}

func (c *Cmdline) wildmenuShow(args []interface{}) {
c.wildmenuShown = true
args = args[0].([]interface{})
c.rawItems = args[0].([]interface{})
palette := editor.palette
palette := c.ws.palette
c.top = 0
for i := 0; i < palette.showTotal; i++ {
resultItem := palette.resultItems[i]
Expand Down Expand Up @@ -195,7 +196,7 @@ func (c *Cmdline) wildmenuShow(args []interface{}) {
func (c *Cmdline) wildmenuSelect(args []interface{}) {
selected := reflectToInt(args[0].([]interface{})[0])
// fmt.Println("selected is", selected)
showTotal := editor.palette.showTotal
showTotal := c.ws.palette.showTotal
if selected == -1 && c.top > 0 {
c.wildmenuScroll(-c.top)
}
Expand All @@ -205,7 +206,7 @@ func (c *Cmdline) wildmenuSelect(args []interface{}) {
if selected >= 0 && selected-c.top < 0 {
c.wildmenuScroll(-1)
}
palette := editor.palette
palette := c.ws.palette
for i := 0; i < palette.showTotal; i++ {
item := palette.resultItems[i]
item.setSelected(selected == i+c.top)
Expand All @@ -214,7 +215,7 @@ func (c *Cmdline) wildmenuSelect(args []interface{}) {

func (c *Cmdline) wildmenuScroll(n int) {
c.top += n
palette := editor.palette
palette := c.ws.palette
for i := 0; i < palette.showTotal; i++ {
resultItem := palette.resultItems[i]
if i >= len(c.rawItems) {
Expand Down
23 changes: 12 additions & 11 deletions editor/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

// Cursor is
type Cursor struct {
ws *Workspace
widget *widgets.QWidget
mode string
x int
Expand All @@ -25,31 +26,31 @@ func initCursorNew() *Cursor {

func (c *Cursor) move() {
c.widget.Move2(c.x, c.y)
editor.loc.widget.Move2(c.x, c.y+editor.font.lineHeight)
c.ws.loc.widget.Move2(c.x, c.y+c.ws.font.lineHeight)
}

func (c *Cursor) updateShape() {
mode := editor.mode
mode := c.ws.mode
if mode == "normal" {
c.widget.Resize2(editor.font.width, editor.font.lineHeight)
c.widget.Resize2(c.ws.font.width, c.ws.font.lineHeight)
c.widget.SetStyleSheet("background-color: rgba(255, 255, 255, 0.5)")
} else if mode == "insert" {
c.widget.Resize2(1, editor.font.lineHeight)
c.widget.Resize2(1, c.ws.font.lineHeight)
c.widget.SetStyleSheet("background-color: rgba(255, 255, 255, 0.9)")
}
}

func (c *Cursor) update() {
if c.mode != editor.mode {
c.mode = editor.mode
if c.mode != c.ws.mode {
c.mode = c.ws.mode
c.updateShape()
}
row := editor.screen.cursor[0]
col := editor.screen.cursor[1]
row := c.ws.screen.cursor[0]
col := c.ws.screen.cursor[1]
if c.row != row || c.col != col {
c.x = int(float64(col) * editor.font.truewidth)
c.y = row * editor.font.lineHeight
c.x = int(float64(col) * c.ws.font.truewidth)
c.y = row * c.ws.font.lineHeight
c.move()
}
editor.screen.tooltip.Move(core.NewQPoint2(c.x, c.y))
c.ws.screen.tooltip.Move(core.NewQPoint2(c.x, c.y))
}
Loading