-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
WIP: Add support for vertical header #679
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,11 +20,12 @@ func (root *Root) draw(ctx context.Context) { | |||||
root.prepareDraw(ctx) | ||||||
|
||||||
// Body. | ||||||
lX := m.topLX | ||||||
lX := root.scr.verticalHeader | ||||||
lN := m.topLN + root.scr.headerEnd | ||||||
// If WrapMode is off, lX is always 0. | ||||||
if !m.WrapMode { | ||||||
lX = 0 | ||||||
|
||||||
// If WrapMode is enabled, the drawing position is adjusted. | ||||||
if m.WrapMode { | ||||||
lX += m.topLX | ||||||
} | ||||||
lX, lN = root.drawBody(lX, lN) | ||||||
m.bottomLX = lX | ||||||
|
@@ -54,6 +55,7 @@ func (root *Root) drawBody(lX int, lN int) (int, int) { | |||||
markStyleWidth := min(root.scr.vWidth, root.Doc.general.MarkStyleWidth) | ||||||
|
||||||
wrapNum := m.numOfWrap(lX, lN) | ||||||
log.Println("wrapNum:", lN, wrapNum, m.width) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to keep this? It looks like a left behind debug There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your comment. |
||||||
for y := m.headerHeight; y < root.scr.vHeight-statusLine; y++ { | ||||||
line, ok := root.scr.lines[lN] | ||||||
if !ok { | ||||||
|
@@ -77,6 +79,7 @@ func (root *Root) drawBody(lX int, lN int) (int, int) { | |||||
wrapNum++ | ||||||
if nextLX == 0 { | ||||||
wrapNum = 0 | ||||||
nextLX = root.scr.verticalHeader | ||||||
} | ||||||
|
||||||
lX = nextLX | ||||||
|
@@ -91,7 +94,7 @@ func (root *Root) drawHeader() { | |||||
|
||||||
// wrapNum is the number of wrapped lines. | ||||||
wrapNum := 0 | ||||||
lX := 0 | ||||||
lX := root.scr.verticalHeader | ||||||
lN := root.scr.headerLN | ||||||
for y := 0; y < m.headerHeight && lN < root.scr.headerEnd; y++ { | ||||||
lineC, ok := root.scr.lines[lN] | ||||||
|
@@ -118,7 +121,7 @@ func (root *Root) drawSectionHeader() { | |||||
m := root.Doc | ||||||
|
||||||
wrapNum := 0 | ||||||
lX := 0 | ||||||
lX := root.scr.verticalHeader | ||||||
lN := root.scr.sectionHeaderLN | ||||||
for y := m.headerHeight; y < m.headerHeight+m.sectionHeaderHeight && lN < root.scr.sectionHeaderEnd; y++ { | ||||||
lineC, ok := root.scr.lines[lN] | ||||||
|
@@ -142,6 +145,7 @@ func (root *Root) drawSectionHeader() { | |||||
wrapNum++ | ||||||
if nextLX == 0 { | ||||||
wrapNum = 0 | ||||||
nextLX = root.scr.verticalHeader | ||||||
} | ||||||
|
||||||
lX = nextLX | ||||||
|
@@ -151,11 +155,40 @@ func (root *Root) drawSectionHeader() { | |||||
|
||||||
// drawWrapLine wraps and draws the contents and returns the next drawing position. | ||||||
func (root *Root) drawLine(y int, lX int, lN int, lineC LineC) (int, int) { | ||||||
if root.scr.verticalHeader > 0 { | ||||||
root.drawVerticalHeader(y, lX, lineC) | ||||||
} | ||||||
if root.Doc.WrapMode { | ||||||
return root.drawWrapLine(y, lX, lN, lineC) | ||||||
} | ||||||
|
||||||
return root.drawNoWrapLine(y, root.Doc.x, lN, lineC) | ||||||
return root.drawNoWrapLine(y, root.scr.verticalHeader+root.Doc.x, lN, lineC) | ||||||
} | ||||||
|
||||||
// drawVerticalHeader draws the vertical header. | ||||||
func (root *Root) drawVerticalHeader(y int, lX int, lineC LineC) { | ||||||
numberWidth := root.scr.numberWidth | ||||||
if numberWidth > 0 { | ||||||
numberWidth += 1 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
screen := root.Screen | ||||||
for n := 0; n < root.scr.verticalHeader; n++ { | ||||||
x := numberWidth + n | ||||||
if lX > root.scr.verticalHeader || n >= len(lineC.lc) { | ||||||
// EOL | ||||||
style := lineC.eolStyle | ||||||
if lineC.valid { | ||||||
style = style.Reverse(true) | ||||||
} | ||||||
root.clearEOL(x, y, style) | ||||||
break | ||||||
} | ||||||
c := lineC.lc[n] | ||||||
if lineC.valid { | ||||||
c.style = c.style.Reverse(true) | ||||||
} | ||||||
screen.SetContent(x, y, c.mainc, c.combc, c.style) | ||||||
} | ||||||
} | ||||||
|
||||||
// drawWrapLine wraps and draws the contents and returns the next drawing position. | ||||||
|
@@ -171,7 +204,7 @@ func (root *Root) drawWrapLine(y int, lX int, lN int, lineC LineC) (int, int) { | |||||
if lX+n >= len(lineC.lc) { | ||||||
// EOL | ||||||
root.clearEOL(x, y, lineC.eolStyle) | ||||||
lX = 0 | ||||||
lX = root.scr.verticalHeader | ||||||
lN++ | ||||||
break | ||||||
} | ||||||
|
@@ -208,8 +241,7 @@ func (root *Root) drawNoWrapLine(y int, lX int, lN int, lineC LineC) (int, int) | |||||
screen.SetContent(x, y, c.mainc, c.combc, c.style) | ||||||
} | ||||||
lN++ | ||||||
|
||||||
return lX, lN | ||||||
return 0, lN | ||||||
} | ||||||
|
||||||
// blankLineNumber should be blank for the line number. | ||||||
|
@@ -220,7 +252,7 @@ func (root *Root) blankLineNumber(y int) { | |||||
if root.scr.startX <= 0 { | ||||||
return | ||||||
} | ||||||
numC := StrToContents(strings.Repeat(" ", root.scr.startX-1), root.Doc.TabWidth) | ||||||
numC := StrToContents(strings.Repeat(" ", root.scr.numberWidth), root.Doc.TabWidth) | ||||||
root.setContentString(0, y, numC) | ||||||
} | ||||||
|
||||||
|
@@ -248,7 +280,7 @@ func (root *Root) drawLineNumber(lN int, y int, valid bool) { | |||||
number = number - m.firstLine() + 1 | ||||||
|
||||||
// Line numbers start at 1 except for skip and header lines. | ||||||
numC := StrToContents(fmt.Sprintf("%*d", root.scr.startX-1, number), m.TabWidth) | ||||||
numC := StrToContents(fmt.Sprintf("%*d", root.scr.numberWidth, number), m.TabWidth) | ||||||
for i := 0; i < len(numC); i++ { | ||||||
numC[i].style = applyStyle(defaultStyle, root.StyleLineNumber) | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,11 @@ type SCR struct { | |
// sectionHeaderEnd is the end of the section header. | ||
sectionHeaderEnd int | ||
|
||
// numWidth is the width of the number. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is so bad, haha I hope it's an AI generated one 🤞 I'm sure something better than this could be suggested |
||
numberWidth int | ||
// verticalHeader is the vertical header. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
verticalHeader int | ||
|
||
// x1, y1, x2, y2 are the coordinates selected by the mouse. | ||
x1 int | ||
y1 int | ||
|
@@ -147,6 +152,8 @@ type general struct { | |
TabWidth int | ||
// Header is number of header lines to be fixed. | ||
Header int | ||
// VerticalHeader is the number of vertical header lines. | ||
VerticalHeader int | ||
// SkipLines is the rows to skip. | ||
SkipLines int | ||
// WatchInterval is the watch interval (seconds). | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,9 @@ func (root *Root) prepareScreen() { | |
|
||
// prepareStartX prepares the start position of the x. | ||
func (root *Root) prepareStartX() { | ||
root.scr.startX = 0 | ||
root.scr.verticalHeader = root.General.VerticalHeader | ||
root.scr.numberWidth = 0 | ||
root.scr.startX = root.scr.verticalHeader | ||
m := root.Doc | ||
if !m.LineNumMode { | ||
return | ||
|
@@ -46,7 +48,8 @@ func (root *Root) prepareStartX() { | |
if m.parent != nil { | ||
m = m.parent | ||
} | ||
root.scr.startX = len(strconv.Itoa(m.BufEndNum())) + 1 | ||
root.scr.numberWidth = len(strconv.Itoa(m.BufEndNum())) | ||
root.scr.startX = root.scr.verticalHeader + root.scr.numberWidth + 1 | ||
} | ||
|
||
// ViewSync redraws the whole thing. | ||
|
@@ -73,7 +76,7 @@ func (root *Root) prepareDraw(ctx context.Context) { | |
root.scr.headerEnd = root.Doc.firstLine() | ||
// Set the header height. | ||
root.Doc.headerHeight = root.Doc.getHeight(root.scr.headerLN, root.scr.headerEnd) | ||
|
||
log.Println("headerHeight:", root.Doc.headerHeight, root.Doc.width) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to keep this log? |
||
// Section header. | ||
root.scr.sectionHeaderLN = -1 | ||
root.scr.sectionHeaderEnd = 0 | ||
|
@@ -306,6 +309,7 @@ func (m *Document) getHeight(startLN int, endLN int) int { | |
for lN := startLN; lN < endLN; lN++ { | ||
height += len(m.leftMostX(lN)) | ||
} | ||
log.Println("height:", startLN, endLN, height) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
return height | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain me this pattern?
The field is an integer, and so here you tell viper to complete the field will the value
1
, why 1? Why not []string{}Is it a way to complete with something that will help user to understand it's a number that is expected?
I had already looked at the code and I was surprised to see this
Here you are doing it again, either on purpose or by copy pasting code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a temporary option, so it doesn't make much sense.
This indicates that an option argument requires numerical values (1 or more).
I thought that the blank ("") wouldn't know what to specify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to make my own test because it looks strange to me