Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cupric
Fzf
Commits
1d8bd11b
Unverified
Commit
1d8bd11b
authored
4 years ago
by
Junegunn Choi
Browse files
Options
Download
Email Patches
Plain Diff
Fix preview window size calculation
parent
bafb99d5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/options.go
+0
-8
src/options.go
src/options_test.go
+9
-8
src/options_test.go
src/terminal.go
+11
-7
src/terminal.go
with
20 additions
and
23 deletions
+20
-23
src/options.go
+
0
-
8
View file @
1d8bd11b
...
...
@@ -1030,14 +1030,6 @@ func parsePreviewWindow(opts *previewOpts, input string) {
}
}
}
if
!
opts
.
size
.
percent
&&
opts
.
size
.
size
>
0
{
// Adjust size for border
opts
.
size
.
size
+=
2
// And padding
if
opts
.
position
==
posLeft
||
opts
.
position
==
posRight
{
opts
.
size
.
size
+=
2
}
}
}
func
parseMargin
(
margin
string
)
[
4
]
sizeSpec
{
...
...
This diff is collapsed.
Click to expand it.
src/options_test.go
+
9
-
8
View file @
1d8bd11b
...
...
@@ -393,17 +393,18 @@ func TestPreviewOpts(t *testing.T) {
opts
.
Preview
.
wrap
==
true
&&
opts
.
Preview
.
position
==
posLeft
&&
opts
.
Preview
.
size
.
percent
==
false
&&
opts
.
Preview
.
size
.
size
==
15
+
2
+
2
)
{
opts
.
Preview
.
size
.
size
==
15
)
{
t
.
Error
(
opts
.
Preview
)
}
opts
=
optsFor
(
"--preview-window=up:15:wrap:hidden"
,
"--preview-window=down"
)
opts
=
optsFor
(
"--preview-window=up:15:wrap:hidden"
,
"--preview-window=down"
,
"--preview-window=cycle"
)
if
!
(
opts
.
Preview
.
command
==
""
&&
opts
.
Preview
.
hidden
==
false
&&
opts
.
Preview
.
wrap
==
false
&&
opts
.
Preview
.
hidden
==
true
&&
opts
.
Preview
.
wrap
==
true
&&
opts
.
Preview
.
cycle
==
true
&&
opts
.
Preview
.
position
==
posDown
&&
opts
.
Preview
.
size
.
percent
==
tru
e
&&
opts
.
Preview
.
size
.
size
==
5
0
)
{
t
.
Error
(
opts
.
Preview
)
opts
.
Preview
.
size
.
percent
==
fals
e
&&
opts
.
Preview
.
size
.
size
==
1
5
)
{
t
.
Error
(
opts
.
Preview
.
size
.
size
)
}
opts
=
optsFor
(
"--preview-window=up:15:wrap:hidden"
)
if
!
(
opts
.
Preview
.
command
==
""
&&
...
...
@@ -411,7 +412,7 @@ func TestPreviewOpts(t *testing.T) {
opts
.
Preview
.
wrap
==
true
&&
opts
.
Preview
.
position
==
posUp
&&
opts
.
Preview
.
size
.
percent
==
false
&&
opts
.
Preview
.
size
.
size
==
15
+
2
)
{
opts
.
Preview
.
size
.
size
==
15
)
{
t
.
Error
(
opts
.
Preview
)
}
}
...
...
This diff is collapsed.
Click to expand it.
src/terminal.go
+
11
-
7
View file @
1d8bd11b
...
...
@@ -614,12 +614,12 @@ const (
maxDisplayWidthCalc
=
1024
)
func
calculateSize
(
base
int
,
size
sizeSpec
,
margin
int
,
minSize
int
)
int
{
max
:=
base
-
margin
func
calculateSize
(
base
int
,
size
sizeSpec
,
occupied
int
,
minSize
int
,
pad
int
)
int
{
max
:=
base
-
occupied
if
size
.
percent
{
return
util
.
Constrain
(
int
(
float64
(
base
)
*
0.01
*
size
.
size
),
minSize
,
max
)
}
return
util
.
Constrain
(
int
(
size
.
size
),
minSize
,
max
)
return
util
.
Constrain
(
int
(
size
.
size
)
+
pad
,
minSize
,
max
)
}
func
(
t
*
Terminal
)
resizeWindows
()
{
...
...
@@ -727,24 +727,28 @@ func (t *Terminal) resizeWindows() {
}
t
.
pwindow
=
t
.
tui
.
NewWindow
(
y
,
x
,
pwidth
,
pheight
,
true
,
noBorder
)
}
verticalPad
:=
2
if
t
.
preview
.
border
==
tui
.
BorderNone
{
verticalPad
=
0
}
switch
t
.
preview
.
position
{
case
posUp
:
pheight
:=
calculateSize
(
height
,
t
.
preview
.
size
,
minHeight
,
3
)
pheight
:=
calculateSize
(
height
,
t
.
preview
.
size
,
minHeight
,
3
,
verticalPad
)
t
.
window
=
t
.
tui
.
NewWindow
(
marginInt
[
0
]
+
pheight
,
marginInt
[
3
],
width
,
height
-
pheight
,
false
,
noBorder
)
createPreviewWindow
(
marginInt
[
0
],
marginInt
[
3
],
width
,
pheight
)
case
posDown
:
pheight
:=
calculateSize
(
height
,
t
.
preview
.
size
,
minHeight
,
3
)
pheight
:=
calculateSize
(
height
,
t
.
preview
.
size
,
minHeight
,
3
,
verticalPad
)
t
.
window
=
t
.
tui
.
NewWindow
(
marginInt
[
0
],
marginInt
[
3
],
width
,
height
-
pheight
,
false
,
noBorder
)
createPreviewWindow
(
marginInt
[
0
]
+
height
-
pheight
,
marginInt
[
3
],
width
,
pheight
)
case
posLeft
:
pwidth
:=
calculateSize
(
width
,
t
.
preview
.
size
,
minWidth
,
5
)
pwidth
:=
calculateSize
(
width
,
t
.
preview
.
size
,
minWidth
,
5
,
4
)
t
.
window
=
t
.
tui
.
NewWindow
(
marginInt
[
0
],
marginInt
[
3
]
+
pwidth
,
width
-
pwidth
,
height
,
false
,
noBorder
)
createPreviewWindow
(
marginInt
[
0
],
marginInt
[
3
],
pwidth
,
height
)
case
posRight
:
pwidth
:=
calculateSize
(
width
,
t
.
preview
.
size
,
minWidth
,
5
)
pwidth
:=
calculateSize
(
width
,
t
.
preview
.
size
,
minWidth
,
5
,
4
)
t
.
window
=
t
.
tui
.
NewWindow
(
marginInt
[
0
],
marginInt
[
3
],
width
-
pwidth
,
height
,
false
,
noBorder
)
createPreviewWindow
(
marginInt
[
0
],
marginInt
[
3
]
+
width
-
pwidth
,
pwidth
,
height
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets