Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
639558ef
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
639558ef
编写于
2月 24, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #20935: Add dragging to the minimap slider
上级
e36134fa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
81 addition
and
1 deletion
+81
-1
src/vs/base/browser/fastDomNode.ts
src/vs/base/browser/fastDomNode.ts
+8
-0
src/vs/editor/browser/viewParts/minimap/minimap.ts
src/vs/editor/browser/viewParts/minimap/minimap.ts
+73
-1
未找到文件。
src/vs/base/browser/fastDomNode.ts
浏览文件 @
639558ef
...
...
@@ -82,6 +82,10 @@ export abstract class FastDomNode<T extends HTMLElement> {
this
.
_domNode
.
style
.
height
=
this
.
_height
+
'
px
'
;
}
public
getHeight
():
number
{
return
this
.
_height
;
}
public
unsetHeight
():
void
{
if
(
this
.
_height
===
-
1
)
{
return
;
...
...
@@ -98,6 +102,10 @@ export abstract class FastDomNode<T extends HTMLElement> {
this
.
_domNode
.
style
.
top
=
this
.
_top
+
'
px
'
;
}
public
getTop
():
number
{
return
this
.
_top
;
}
public
unsetTop
():
void
{
if
(
this
.
_top
===
-
1
)
{
return
;
...
...
src/vs/editor/browser/viewParts/minimap/minimap.ts
浏览文件 @
639558ef
...
...
@@ -24,6 +24,8 @@ import { RenderedLinesCollection, ILine } from 'vs/editor/browser/view/viewLayer
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
RGBA
}
from
'
vs/base/common/color
'
;
import
*
as
viewEvents
from
'
vs/editor/common/view/viewEvents
'
;
import
{
GlobalMouseMoveMonitor
,
IStandardMouseMoveEventData
,
standardMouseMoveMerger
}
from
'
vs/base/browser/globalMouseMoveMonitor
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
const
enum
RenderMinimap
{
None
=
0
,
...
...
@@ -61,6 +63,11 @@ function getMinimapCharWidth(renderMinimap: RenderMinimap): number {
return
Constants
.
x1_CHAR_WIDTH
;
}
/**
* The orthogonal distance to the slider at which dragging "resets". This implements "snapping"
*/
const
MOUSE_DRAG_RESET_DISTANCE
=
140
;
class
MinimapOptions
{
public
readonly
renderMinimap
:
RenderMinimap
;
...
...
@@ -241,7 +248,17 @@ class MinimapLayout {
}
this
.
sliderTop
=
Math
.
floor
((
viewportStartLineNumber
-
this
.
startLineNumber
)
*
minimapLineHeight
/
pixelRatio
);
this
.
sliderHeight
=
Math
.
floor
(
viewportLineCount
*
minimapLineHeight
/
pixelRatio
);
if
(
viewportEndLineNumber
===
lineCount
)
{
// The last line is in the viewport => try to extend slider height below the painted lines
let
desiredSliderHeight
=
Math
.
floor
(
expectedViewportLineCount
*
minimapLineHeight
/
pixelRatio
);
if
(
this
.
sliderTop
+
desiredSliderHeight
>
options
.
minimapHeight
)
{
this
.
sliderHeight
=
options
.
minimapHeight
-
this
.
sliderTop
;
}
else
{
this
.
sliderHeight
=
desiredSliderHeight
;
}
}
else
{
this
.
sliderHeight
=
Math
.
floor
(
viewportLineCount
*
minimapLineHeight
/
pixelRatio
);
}
}
}
...
...
@@ -404,6 +421,8 @@ export class Minimap extends ViewPart {
private
readonly
_slider
:
FastDomNode
<
HTMLElement
>
;
private
readonly
_tokensColorTracker
:
MinimapTokensColorTracker
;
private
readonly
_mouseDownListener
:
IDisposable
;
private
readonly
_sliderMouseMoveMonitor
:
GlobalMouseMoveMonitor
<
IStandardMouseMoveEventData
>
;
private
readonly
_sliderMouseDownListener
:
IDisposable
;
private
readonly
_minimapCharRenderer
:
MinimapCharRenderer
;
...
...
@@ -468,10 +487,63 @@ export class Minimap extends ViewPart {
false
));
});
this
.
_sliderMouseMoveMonitor
=
new
GlobalMouseMoveMonitor
<
IStandardMouseMoveEventData
>
();
this
.
_sliderMouseDownListener
=
dom
.
addStandardDisposableListener
(
this
.
_slider
.
domNode
,
'
mousedown
'
,
(
e
)
=>
{
e
.
preventDefault
();
if
(
e
.
leftButton
)
{
const
initialMouseOrthogonalPosition
=
e
.
posx
;
const
initialScrollTop
=
this
.
_viewLayout
.
getScrollTop
();
const
initialSliderCenter
=
(
this
.
_slider
.
getTop
()
+
this
.
_slider
.
getHeight
()
/
2
);
const
draggingDeltaCenter
=
e
.
posy
-
initialSliderCenter
;
this
.
_slider
.
toggleClassName
(
'
active
'
,
true
);
this
.
_sliderMouseMoveMonitor
.
startMonitoring
(
standardMouseMoveMerger
,
(
mouseMoveData
:
IStandardMouseMoveEventData
)
=>
{
const
mouseOrthogonalPosition
=
mouseMoveData
.
posx
;
const
mouseOrthogonalDelta
=
Math
.
abs
(
mouseOrthogonalPosition
-
initialMouseOrthogonalPosition
);
if
(
platform
.
isWindows
&&
mouseOrthogonalDelta
>
MOUSE_DRAG_RESET_DISTANCE
)
{
// The mouse has wondered away from the slider => reset dragging
this
.
_viewLayout
.
setScrollPosition
({
scrollTop
:
initialScrollTop
});
}
else
{
const
pixelRatio
=
this
.
_options
.
pixelRatio
;
const
minimapLineHeight
=
getMinimapLineHeight
(
this
.
_options
.
renderMinimap
);
const
entireCanvasOuterHeight
=
this
.
_context
.
model
.
getLineCount
()
*
minimapLineHeight
/
pixelRatio
;
const
representableHeight
=
Math
.
min
(
entireCanvasOuterHeight
,
this
.
_options
.
canvasOuterHeight
);
// Account for the fact that the minimap does not render the extra space below the viewport
let
discountScrollHeight
=
0
;
if
(
this
.
_context
.
configuration
.
editor
.
viewInfo
.
scrollBeyondLastLine
)
{
discountScrollHeight
=
this
.
_canvas
.
getHeight
()
-
this
.
_context
.
configuration
.
editor
.
lineHeight
;
}
const
scrollHeight
=
this
.
_viewLayout
.
getScrollHeight
()
-
discountScrollHeight
;
const
desiredSliderCenter
=
mouseMoveData
.
posy
-
draggingDeltaCenter
;
const
desiredScrollCenter
=
desiredSliderCenter
*
(
scrollHeight
/
representableHeight
);
const
desiredScrollTop
=
desiredScrollCenter
-
this
.
_canvas
.
getHeight
()
/
2
;
this
.
_viewLayout
.
setScrollPosition
({
scrollTop
:
desiredScrollTop
});
}
},
()
=>
{
this
.
_slider
.
toggleClassName
(
'
active
'
,
false
);
}
);
}
});
}
public
dispose
():
void
{
this
.
_mouseDownListener
.
dispose
();
this
.
_sliderMouseMoveMonitor
.
dispose
();
this
.
_sliderMouseDownListener
.
dispose
();
super
.
dispose
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录