Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
dcbe78a1
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,发现更多精彩内容 >>
提交
dcbe78a1
编写于
5月 19, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The cursor gets passed in the ViewModel
上级
7a765323
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
150 addition
and
224 deletion
+150
-224
src/vs/editor/common/commonCodeEditor.ts
src/vs/editor/common/commonCodeEditor.ts
+2
-19
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+20
-1
src/vs/editor/common/viewModel/viewModel.ts
src/vs/editor/common/viewModel/viewModel.ts
+4
-0
src/vs/editor/test/common/commands/commandTestUtils.ts
src/vs/editor/test/common/commands/commandTestUtils.ts
+8
-13
src/vs/editor/test/common/commands/sideEditing.test.ts
src/vs/editor/test/common/commands/sideEditing.test.ts
+9
-15
src/vs/editor/test/common/controller/cursor.test.ts
src/vs/editor/test/common/controller/cursor.test.ts
+72
-56
src/vs/editor/test/common/controller/cursorMoveCommand.test.ts
...s/editor/test/common/controller/cursorMoveCommand.test.ts
+14
-64
src/vs/editor/test/common/editorTestUtils.ts
src/vs/editor/test/common/editorTestUtils.ts
+0
-50
src/vs/editor/test/common/mocks/mockCodeEditor.ts
src/vs/editor/test/common/mocks/mockCodeEditor.ts
+21
-6
未找到文件。
src/vs/editor/common/commonCodeEditor.ts
浏览文件 @
dcbe78a1
...
...
@@ -13,7 +13,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import
{
IContextKey
,
IContextKeyServiceTarget
,
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
CommonEditorConfiguration
}
from
'
vs/editor/common/config/commonEditorConfig
'
;
import
{
Cursor
}
from
'
vs/editor/common/controller/cursor
'
;
import
{
CursorColumns
,
I
ViewModelHelper
,
I
Cursors
,
CursorConfiguration
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
CursorColumns
,
ICursors
,
CursorConfiguration
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Position
,
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
,
ISelection
}
from
'
vs/editor/common/core/selection
'
;
...
...
@@ -863,23 +863,6 @@ export abstract class CommonCodeEditor extends Disposable implements editorCommo
this
.
viewModel
=
new
ViewModel
(
this
.
id
,
this
.
_configuration
,
this
.
model
);
let
viewModelHelper
:
IViewModelHelper
=
{
viewModel
:
this
.
viewModel
,
coordinatesConverter
:
this
.
viewModel
.
coordinatesConverter
,
getScrollTop
:
():
number
=>
{
return
this
.
viewModel
.
viewLayout
.
getScrollTop
();
},
getCompletelyVisibleViewRange
:
():
Range
=>
{
return
this
.
viewModel
.
getCompletelyVisibleViewRange
();
},
getCompletelyVisibleViewRangeAtScrollTop
:
(
scrollTop
:
number
):
Range
=>
{
return
this
.
viewModel
.
getCompletelyVisibleViewRangeAtScrollTop
(
scrollTop
);
},
getVerticalOffsetForViewLineNumber
:
(
viewLineNumber
:
number
):
number
=>
{
return
this
.
viewModel
.
viewLayout
.
getVerticalOffsetForLineNumber
(
viewLineNumber
);
}
};
this
.
listenersToRemove
.
push
(
this
.
model
.
addBulkListener
((
events
)
=>
{
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
let
eventType
=
events
[
i
].
type
;
...
...
@@ -917,7 +900,7 @@ export abstract class CommonCodeEditor extends Disposable implements editorCommo
this
.
cursor
=
new
Cursor
(
this
.
_configuration
,
this
.
model
,
viewModelHelper
this
.
viewModel
);
this
.
viewCursor
=
new
ViewModelCursors
(
...
...
src/vs/editor/common/controller/cursor.ts
浏览文件 @
dcbe78a1
...
...
@@ -20,6 +20,7 @@ import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperat
import
{
TypeOperations
}
from
'
vs/editor/common/controller/cursorTypeOperations
'
;
import
{
TextModelEventType
,
ModelRawContentChangedEvent
,
RawContentChangedType
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
CursorEventType
,
CursorChangeReason
,
ICursorPositionChangedEvent
,
VerticalRevealType
,
ICursorSelectionChangedEvent
,
ICursorRevealRangeEvent
,
CursorScrollRequest
}
from
'
vs/editor/common/controller/cursorEvents
'
;
import
{
IViewModel
}
from
"
vs/editor/common/viewModel/viewModel
"
;
export
class
Cursor
extends
Disposable
implements
ICursors
{
...
...
@@ -44,11 +45,29 @@ export class Cursor extends Disposable implements ICursors {
private
_isDoingComposition
:
boolean
;
private
_columnSelectData
:
IColumnSelectData
;
constructor
(
configuration
:
editorCommon
.
IConfiguration
,
model
:
editorCommon
.
IModel
,
viewModel
Helper
:
IViewModelHelper
)
{
constructor
(
configuration
:
editorCommon
.
IConfiguration
,
model
:
editorCommon
.
IModel
,
viewModel
:
IViewModel
)
{
super
();
this
.
_eventEmitter
=
this
.
_register
(
new
EventEmitter
());
this
.
_configuration
=
configuration
;
this
.
_model
=
model
;
let
viewModelHelper
:
IViewModelHelper
=
{
viewModel
:
viewModel
,
coordinatesConverter
:
viewModel
.
coordinatesConverter
,
getScrollTop
:
():
number
=>
{
return
viewModel
.
viewLayout
.
getScrollTop
();
},
getCompletelyVisibleViewRange
:
():
Range
=>
{
return
viewModel
.
getCompletelyVisibleViewRange
();
},
getCompletelyVisibleViewRangeAtScrollTop
:
(
scrollTop
:
number
):
Range
=>
{
return
viewModel
.
getCompletelyVisibleViewRangeAtScrollTop
(
scrollTop
);
},
getVerticalOffsetForViewLineNumber
:
(
viewLineNumber
:
number
):
number
=>
{
return
viewModel
.
viewLayout
.
getVerticalOffsetForLineNumber
(
viewLineNumber
);
}
};
this
.
_viewModelHelper
=
viewModelHelper
;
this
.
context
=
new
CursorContext
(
this
.
_configuration
,
this
.
_model
,
this
.
_viewModelHelper
);
this
.
_cursors
=
new
CursorCollection
(
this
.
context
);
...
...
src/vs/editor/common/viewModel/viewModel.ts
浏览文件 @
dcbe78a1
...
...
@@ -120,6 +120,8 @@ export interface IViewModel {
getDecorationsInViewport
(
visibleRange
:
Range
):
ViewModelDecoration
[];
getViewLineRenderingData
(
visibleRange
:
Range
,
lineNumber
:
number
):
ViewLineRenderingData
;
getMinimapLinesRenderingData
(
startLineNumber
:
number
,
endLineNumber
:
number
,
needed
:
boolean
[]):
MinimapLinesRenderingData
;
getCompletelyVisibleViewRange
():
Range
;
getCompletelyVisibleViewRangeAtScrollTop
(
scrollTop
:
number
):
Range
;
getTabSize
():
number
;
getLineCount
():
number
;
...
...
@@ -127,6 +129,8 @@ export interface IViewModel {
getLineIndentGuide
(
lineNumber
:
number
):
number
;
getLineMinColumn
(
lineNumber
:
number
):
number
;
getLineMaxColumn
(
lineNumber
:
number
):
number
;
getLineFirstNonWhitespaceColumn
(
lineNumber
:
number
):
number
;
getLineLastNonWhitespaceColumn
(
lineNumber
:
number
):
number
;
getAllOverviewRulerDecorations
():
ViewModelDecoration
[];
getValueInRange
(
range
:
Range
,
eol
:
EndOfLinePreference
):
string
;
...
...
src/vs/editor/test/common/commands/commandTestUtils.ts
浏览文件 @
dcbe78a1
...
...
@@ -5,14 +5,12 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Cursor
}
from
'
vs/editor/common/controller/cursor
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
{
LanguageIdentifier
}
from
'
vs/editor/common/modes
'
;
import
{
TestConfiguration
}
from
'
vs/editor/test/common/mocks/testConfiguration
'
;
import
{
viewModelHelper
}
from
'
vs/editor/test/common/editorTestUtils
'
;
import
{
withMockCodeEditor
}
from
"
vs/editor/test/common/mocks/mockCodeEditor
"
;
export
function
testCommand
(
lines
:
string
[],
...
...
@@ -22,10 +20,8 @@ export function testCommand(
expectedLines
:
string
[],
expectedSelection
:
Selection
):
void
{
let
model
=
Model
.
createFromString
(
lines
.
join
(
'
\n
'
),
undefined
,
languageIdentifier
);
let
config
=
new
TestConfiguration
(
null
);
let
cursor
=
new
Cursor
(
config
,
model
,
viewModelHelper
(
model
));
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
cursor
.
setSelections
(
'
tests
'
,
[
selection
]);
...
...
@@ -36,8 +32,7 @@ export function testCommand(
let
actualSelection
=
cursor
.
getSelection
();
assert
.
deepEqual
(
actualSelection
.
toString
(),
expectedSelection
.
toString
());
cursor
.
dispose
();
config
.
dispose
();
});
model
.
dispose
();
}
...
...
src/vs/editor/test/common/commands/sideEditing.test.ts
浏览文件 @
dcbe78a1
...
...
@@ -5,23 +5,19 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Cursor
}
from
'
vs/editor/common/controller/cursor
'
;
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
IIdentifiedSingleEditOperation
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
{
ILineEdit
,
ModelLine
,
LineMarker
,
MarkersTracker
}
from
'
vs/editor/common/model/modelLine
'
;
import
{
TestConfiguration
}
from
'
vs/editor/test/common/mocks/testConfiguration
'
;
import
{
viewModelHelper
}
from
'
vs/editor/test/common/editorTestUtils
'
;
import
{
withMockCodeEditor
}
from
"
vs/editor/test/common/mocks/mockCodeEditor
"
;
const
NO_TAB_SIZE
=
0
;
function
testCommand
(
lines
:
string
[],
selections
:
Selection
[],
edits
:
IIdentifiedSingleEditOperation
[],
expectedLines
:
string
[],
expectedSelections
:
Selection
[]):
void
{
let
model
=
Model
.
createFromString
(
lines
.
join
(
'
\n
'
));
let
config
=
new
TestConfiguration
(
null
);
let
cursor
=
new
Cursor
(
config
,
model
,
viewModelHelper
(
model
));
withMockCodeEditor
(
lines
,
{},
(
editor
,
cursor
)
=>
{
const
model
=
editor
.
getModel
();
cursor
.
setSelections
(
'
tests
'
,
selections
);
...
...
@@ -32,9 +28,7 @@ function testCommand(lines: string[], selections: Selection[], edits: IIdentifie
let
actualSelections
=
cursor
.
getSelections
();
assert
.
deepEqual
(
actualSelections
.
map
(
s
=>
s
.
toString
()),
expectedSelections
.
map
(
s
=>
s
.
toString
()));
cursor
.
dispose
();
config
.
dispose
();
model
.
dispose
();
});
}
function
testLineEditMarker
(
text
:
string
,
column
:
number
,
stickToPreviousCharacter
:
boolean
,
edit
:
ILineEdit
,
expectedColumn
:
number
):
void
{
...
...
src/vs/editor/test/common/controller/cursor.test.ts
浏览文件 @
dcbe78a1
...
...
@@ -21,12 +21,12 @@ import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageCo
import
{
TestConfiguration
}
from
'
vs/editor/test/common/mocks/testConfiguration
'
;
import
{
MockMode
}
from
'
vs/editor/test/common/mocks/mockMode
'
;
import
{
LanguageIdentifier
}
from
'
vs/editor/common/modes
'
;
import
{
viewModelHelper
}
from
'
vs/editor/test/common/editorTestUtils
'
;
import
{
IEditorOptions
}
from
'
vs/editor/common/config/editorOptions
'
;
import
{
ICursorPositionChangedEvent
,
ICursorSelectionChangedEvent
}
from
'
vs/editor/common/controller/cursorEvents
'
;
import
{
CoreNavigationCommands
,
CoreEditingCommands
}
from
'
vs/editor/common/controller/coreCommands
'
;
import
{
withMockCodeEditor
}
from
"
vs/editor/test/common/mocks/mockCodeEditor
"
;
import
{
TextModel
}
from
"
vs/editor/common/model/textModel
"
;
import
{
ViewModel
}
from
"
vs/editor/common/viewModel/viewModelImpl
"
;
let
H
=
Handler
;
...
...
@@ -136,6 +136,7 @@ suite('Editor Controller - Cursor', () => {
let
thisModel
:
Model
;
let
thisConfiguration
:
TestConfiguration
;
let
thisViewModel
:
ViewModel
;
let
thisCursor
:
Cursor
;
setup
(()
=>
{
...
...
@@ -148,11 +149,14 @@ suite('Editor Controller - Cursor', () => {
thisModel
=
Model
.
createFromString
(
text
);
thisConfiguration
=
new
TestConfiguration
(
null
);
thisCursor
=
new
Cursor
(
thisConfiguration
,
thisModel
,
viewModelHelper
(
thisModel
));
thisViewModel
=
new
ViewModel
(
0
,
thisConfiguration
,
thisModel
);
thisCursor
=
new
Cursor
(
thisConfiguration
,
thisModel
,
thisViewModel
);
});
teardown
(()
=>
{
thisCursor
.
dispose
();
thisViewModel
.
dispose
();
thisModel
.
dispose
();
thisConfiguration
.
dispose
();
});
...
...
@@ -700,14 +704,13 @@ suite('Editor Controller - Cursor', () => {
});
test
(
'
column select 1
'
,
()
=>
{
let
model
=
Model
.
createFromString
([
withMockCodeEditor
([
'
\t
private compute(a:number): boolean {
'
,
'
\t\t
if (a + 3 === 0 || a + 5 === 0) {
'
,
'
\t\t\t
return false;
'
,
'
\t\t
}
'
,
'
\t
}
'
].
join
(
'
\n
'
));
let
cursor
=
new
Cursor
(
new
TestConfiguration
(
null
),
model
,
viewModelHelper
(
model
));
],
{},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
1
,
7
,
false
);
assertCursor
(
cursor
,
new
Position
(
1
,
7
));
...
...
@@ -727,12 +730,11 @@ suite('Editor Controller - Cursor', () => {
assertCursor
(
cursor
,
expectedSelections
);
cursor
.
dispose
();
model
.
dispose
();
});
});
test
(
'
issue #4905 - column select is biased to the right
'
,
()
=>
{
le
t
model
=
Model
.
createFromString
([
cons
t
model
=
Model
.
createFromString
([
'
var gulp = require("gulp");
'
,
'
var path = require("path");
'
,
'
var rimraf = require("rimraf");
'
,
...
...
@@ -741,7 +743,9 @@ suite('Editor Controller - Cursor', () => {
'
var concat = require("gulp-concat");
'
,
'
var newer = require("gulp-newer");
'
,
].
join
(
'
\n
'
));
let
cursor
=
new
Cursor
(
new
TestConfiguration
(
null
),
model
,
viewModelHelper
(
model
));
const
config
=
new
TestConfiguration
(
null
);
const
viewModel
=
new
ViewModel
(
0
,
config
,
model
);
const
cursor
=
new
Cursor
(
config
,
model
,
viewModel
);
moveTo
(
cursor
,
1
,
4
,
false
);
assertCursor
(
cursor
,
new
Position
(
1
,
4
));
...
...
@@ -760,11 +764,13 @@ suite('Editor Controller - Cursor', () => {
]);
cursor
.
dispose
();
viewModel
.
dispose
();
config
.
dispose
();
model
.
dispose
();
});
test
(
'
issue #20087: column select with mouse
'
,
()
=>
{
le
t
model
=
Model
.
createFromString
([
cons
t
model
=
Model
.
createFromString
([
'
<property id="SomeThing" key="SomeKey" value="000"/>
'
,
'
<property id="SomeThing" key="SomeKey" value="000"/>
'
,
'
<property id="SomeThing" Key="SomeKey" value="000"/>
'
,
...
...
@@ -776,7 +782,9 @@ suite('Editor Controller - Cursor', () => {
'
<property id="SomeThing" key="SomeKey" value="000"/>
'
,
'
<property id="SomeThing" key="SomeKey" value="00X"/>
'
,
].
join
(
'
\n
'
));
let
cursor
=
new
Cursor
(
new
TestConfiguration
(
null
),
model
,
viewModelHelper
(
model
));
const
config
=
new
TestConfiguration
(
null
);
const
viewModel
=
new
ViewModel
(
0
,
config
,
model
);
const
cursor
=
new
Cursor
(
config
,
model
,
viewModel
);
moveTo
(
cursor
,
10
,
10
,
false
);
assertCursor
(
cursor
,
new
Position
(
10
,
10
));
...
...
@@ -818,11 +826,13 @@ suite('Editor Controller - Cursor', () => {
]);
cursor
.
dispose
();
viewModel
.
dispose
();
config
.
dispose
();
model
.
dispose
();
});
test
(
'
issue #20087: column select with keyboard
'
,
()
=>
{
le
t
model
=
Model
.
createFromString
([
cons
t
model
=
Model
.
createFromString
([
'
<property id="SomeThing" key="SomeKey" value="000"/>
'
,
'
<property id="SomeThing" key="SomeKey" value="000"/>
'
,
'
<property id="SomeThing" Key="SomeKey" value="000"/>
'
,
...
...
@@ -834,7 +844,9 @@ suite('Editor Controller - Cursor', () => {
'
<property id="SomeThing" key="SomeKey" value="000"/>
'
,
'
<property id="SomeThing" key="SomeKey" value="00X"/>
'
,
].
join
(
'
\n
'
));
let
cursor
=
new
Cursor
(
new
TestConfiguration
(
null
),
model
,
viewModelHelper
(
model
));
const
config
=
new
TestConfiguration
(
null
);
const
viewModel
=
new
ViewModel
(
0
,
config
,
model
);
const
cursor
=
new
Cursor
(
config
,
model
,
viewModel
);
moveTo
(
cursor
,
10
,
10
,
false
);
assertCursor
(
cursor
,
new
Position
(
10
,
10
));
...
...
@@ -866,11 +878,13 @@ suite('Editor Controller - Cursor', () => {
]);
cursor
.
dispose
();
viewModel
.
dispose
();
config
.
dispose
();
model
.
dispose
();
});
test
(
'
column select with keyboard
'
,
()
=>
{
le
t
model
=
Model
.
createFromString
([
cons
t
model
=
Model
.
createFromString
([
'
var gulp = require("gulp");
'
,
'
var path = require("path");
'
,
'
var rimraf = require("rimraf");
'
,
...
...
@@ -879,7 +893,9 @@ suite('Editor Controller - Cursor', () => {
'
var concat = require("gulp-concat");
'
,
'
var newer = require("gulp-newer");
'
,
].
join
(
'
\n
'
));
let
cursor
=
new
Cursor
(
new
TestConfiguration
(
null
),
model
,
viewModelHelper
(
model
));
const
config
=
new
TestConfiguration
(
null
);
const
viewModel
=
new
ViewModel
(
0
,
config
,
model
);
const
cursor
=
new
Cursor
(
config
,
model
,
viewModel
);
moveTo
(
cursor
,
1
,
4
,
false
);
assertCursor
(
cursor
,
new
Position
(
1
,
4
));
...
...
@@ -1076,6 +1092,8 @@ suite('Editor Controller - Cursor', () => {
]);
cursor
.
dispose
();
viewModel
.
dispose
();
config
.
dispose
();
model
.
dispose
();
});
});
...
...
@@ -1438,13 +1456,13 @@ suite('Editor Controller - Regression tests', () => {
});
test
(
'
bug #16740: [editor] Cut line doesn
\'
t quite cut the last line
'
,
()
=>
{
// Part 1 => there is text on the last line
let
text
=
[
withMockCodeEditor
(
[
'
asdasd
'
,
'
qwerty
'
];
let
model
=
Model
.
createFromString
(
text
.
join
(
'
\n
'
));
let
cursor
=
new
Cursor
(
new
TestConfiguration
(
null
),
model
,
viewModelHelper
(
model
));
],
{},
(
editor
,
cursor
)
=>
{
const
model
=
editor
.
getModel
();
moveTo
(
cursor
,
2
,
1
,
false
);
assertCursor
(
cursor
,
new
Selection
(
2
,
1
,
2
,
1
));
...
...
@@ -1453,16 +1471,14 @@ suite('Editor Controller - Regression tests', () => {
assert
.
equal
(
model
.
getLineCount
(),
1
);
assert
.
equal
(
model
.
getLineContent
(
1
),
'
asdasd
'
);
cursor
.
dispose
();
model
.
dispose
();
});
// Part 2 => there is no text on the last line
text
=
[
withMockCodeEditor
(
[
'
asdasd
'
,
''
];
model
=
Model
.
createFromString
(
text
.
join
(
'
\n
'
));
cursor
=
new
Cursor
(
new
TestConfiguration
(
null
),
model
,
viewModelHelper
(
model
));
],
{},
(
editor
,
cursor
)
=>
{
const
model
=
editor
.
getModel
();
moveTo
(
cursor
,
2
,
1
,
false
);
assertCursor
(
cursor
,
new
Selection
(
2
,
1
,
2
,
1
));
...
...
@@ -1474,9 +1490,7 @@ suite('Editor Controller - Regression tests', () => {
cursorCommand
(
cursor
,
H
.
Cut
,
null
,
'
keyboard
'
);
assert
.
equal
(
model
.
getLineCount
(),
1
);
assert
.
equal
(
model
.
getLineContent
(
1
),
''
);
cursor
.
dispose
();
model
.
dispose
();
});
});
test
(
'
Bug #11476: Double bracket surrounding + undo is broken
'
,
()
=>
{
...
...
@@ -2756,11 +2770,13 @@ interface ICursorOpts {
function
usingCursor
(
opts
:
ICursorOpts
,
callback
:
(
model
:
Model
,
cursor
:
Cursor
)
=>
void
):
void
{
let
model
=
Model
.
createFromString
(
opts
.
text
.
join
(
'
\n
'
),
opts
.
modelOpts
,
opts
.
languageIdentifier
);
let
config
=
new
TestConfiguration
(
opts
.
editorOpts
);
let
cursor
=
new
Cursor
(
config
,
model
,
viewModelHelper
(
model
));
let
viewModel
=
new
ViewModel
(
0
,
config
,
model
);
let
cursor
=
new
Cursor
(
config
,
model
,
viewModel
);
callback
(
model
,
cursor
);
cursor
.
dispose
();
viewModel
.
dispose
();
config
.
dispose
();
model
.
dispose
();
}
...
...
src/vs/editor/test/common/controller/cursorMoveCommand.test.ts
浏览文件 @
dcbe78a1
...
...
@@ -11,18 +11,18 @@ import { ITextModelCreationOptions } from 'vs/editor/common/editorCommon';
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
{
IMode
}
from
'
vs/editor/common/modes
'
;
import
{
TestConfiguration
}
from
'
vs/editor/test/common/mocks/testConfiguration
'
;
import
{
viewModelHelper
as
aViewModelHelper
}
from
'
vs/editor/test/common/editorTestUtils
'
;
import
{
CursorMove
}
from
'
vs/editor/common/controller/cursorMoveCommands
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
IEditorOptions
}
from
'
vs/editor/common/config/editorOptions
'
;
import
{
IViewModelHelper
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
CoreNavigationCommands
}
from
'
vs/editor/common/controller/coreCommands
'
;
import
{
ViewModel
}
from
"
vs/editor/common/viewModel/viewModelImpl
"
;
suite
(
'
Cursor move command test
'
,
()
=>
{
let
thisModel
:
Model
;
let
thisConfiguration
:
TestConfiguration
;
let
thisViewModel
:
ViewModel
;
let
thisCursor
:
Cursor
;
setup
(()
=>
{
...
...
@@ -36,16 +36,18 @@ suite('Cursor move command test', () => {
thisModel
=
Model
.
createFromString
(
text
);
thisConfiguration
=
new
TestConfiguration
(
null
);
thisViewModel
=
new
ViewModel
(
0
,
thisConfiguration
,
thisModel
);
thisCursor
=
new
Cursor
(
thisConfiguration
,
thisModel
,
thisViewModel
);
});
teardown
(()
=>
{
thisCursor
.
dispose
();
thisViewModel
.
dispose
();
thisModel
.
dispose
();
thisConfiguration
.
dispose
();
});
test
(
'
move left should move to left character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveLeft
(
thisCursor
);
...
...
@@ -54,7 +56,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move left should move to left by n characters
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveLeft
(
thisCursor
,
3
);
...
...
@@ -63,7 +64,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move left should move to left by half line
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveLeft
(
thisCursor
,
1
,
CursorMove
.
RawUnit
.
HalfLine
);
...
...
@@ -72,7 +72,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move left moves to previous line
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
2
,
3
);
moveLeft
(
thisCursor
,
10
);
...
...
@@ -81,7 +80,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move right should move to right character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
5
);
moveRight
(
thisCursor
);
...
...
@@ -90,7 +88,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move right should move to right by n characters
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
2
);
moveRight
(
thisCursor
,
6
);
...
...
@@ -99,7 +96,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move right should move to right by half line
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
4
);
moveRight
(
thisCursor
,
1
,
CursorMove
.
RawUnit
.
HalfLine
);
...
...
@@ -108,7 +104,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move right moves to next line
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveRight
(
thisCursor
,
100
);
...
...
@@ -117,14 +112,12 @@ suite('Cursor move command test', () => {
});
test
(
'
move to first character of line from middle
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveToLineStart
(
thisCursor
);
cursorEqual
(
thisCursor
,
1
,
1
);
});
test
(
'
move to first character of line from first non white space character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
6
);
moveToLineStart
(
thisCursor
);
...
...
@@ -133,7 +126,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to first character of line from first character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
1
);
moveToLineStart
(
thisCursor
);
...
...
@@ -142,7 +134,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to first non white space character of line from middle
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveToLineFirstNonWhiteSpaceCharacter
(
thisCursor
);
...
...
@@ -151,7 +142,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to first non white space character of line from first non white space character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
6
);
moveToLineFirstNonWhiteSpaceCharacter
(
thisCursor
);
...
...
@@ -160,7 +150,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to first non white space character of line from first character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
1
);
moveToLineFirstNonWhiteSpaceCharacter
(
thisCursor
);
...
...
@@ -169,7 +158,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to end of line from middle
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveToLineEnd
(
thisCursor
);
...
...
@@ -178,7 +166,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to end of line from last non white space character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
19
);
moveToLineEnd
(
thisCursor
);
...
...
@@ -187,7 +174,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to end of line from line end
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
21
);
moveToLineEnd
(
thisCursor
);
...
...
@@ -196,7 +182,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to last non white space character from middle
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveToLineLastNonWhiteSpaceCharacter
(
thisCursor
);
...
...
@@ -205,7 +190,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to last non white space character from last non white space character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
19
);
moveToLineLastNonWhiteSpaceCharacter
(
thisCursor
);
...
...
@@ -214,7 +198,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to last non white space character from line end
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
21
);
moveToLineLastNonWhiteSpaceCharacter
(
thisCursor
);
...
...
@@ -223,7 +206,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to center of line not from center
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveToLineCenter
(
thisCursor
);
...
...
@@ -232,7 +214,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to center of line from center
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
11
);
moveToLineCenter
(
thisCursor
);
...
...
@@ -241,7 +222,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to center of line from start
'
,
()
=>
{
thisCursor
=
aCursor
();
moveToLineStart
(
thisCursor
);
moveToLineCenter
(
thisCursor
);
...
...
@@ -250,7 +230,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move to center of line from end
'
,
()
=>
{
thisCursor
=
aCursor
();
moveToLineEnd
(
thisCursor
);
moveToLineCenter
(
thisCursor
);
...
...
@@ -259,7 +238,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move up by cursor move command
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
3
,
5
);
cursorEqual
(
thisCursor
,
3
,
5
);
...
...
@@ -272,7 +250,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move up by model line cursor move command
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
3
,
5
);
cursorEqual
(
thisCursor
,
3
,
5
);
...
...
@@ -285,7 +262,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move down by model line cursor move command
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
3
,
5
);
cursorEqual
(
thisCursor
,
3
,
5
);
...
...
@@ -298,7 +274,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move up with selection by cursor move command
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
3
,
5
);
cursorEqual
(
thisCursor
,
3
,
5
);
...
...
@@ -311,7 +286,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move up and down with tabs by cursor move command
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
5
);
cursorEqual
(
thisCursor
,
1
,
5
);
...
...
@@ -333,7 +307,6 @@ suite('Cursor move command test', () => {
});
test
(
'
move up and down with end of lines starting from a long one by cursor move command
'
,
()
=>
{
thisCursor
=
aCursor
();
moveToEndOfLine
(
thisCursor
);
cursorEqual
(
thisCursor
,
1
,
21
);
...
...
@@ -355,9 +328,7 @@ suite('Cursor move command test', () => {
});
test
(
'
move to view top line moves to first visible line if it is first line
'
,
()
=>
{
let
viewModelHelper
=
aViewModelHelper
(
thisModel
);
viewModelHelper
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
10
,
1
);
thisCursor
=
aCursor
(
viewModelHelper
);
thisViewModel
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
10
,
1
);
moveTo
(
thisCursor
,
2
,
2
);
moveToTop
(
thisCursor
);
...
...
@@ -366,9 +337,7 @@ suite('Cursor move command test', () => {
});
test
(
'
move to view top line moves to top visible line when first line is not visible
'
,
()
=>
{
let
viewModelHelper
=
aViewModelHelper
(
thisModel
);
viewModelHelper
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
2
,
1
,
10
,
1
);
thisCursor
=
aCursor
(
viewModelHelper
);
thisViewModel
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
2
,
1
,
10
,
1
);
moveTo
(
thisCursor
,
4
,
1
);
moveToTop
(
thisCursor
);
...
...
@@ -377,9 +346,7 @@ suite('Cursor move command test', () => {
});
test
(
'
move to view top line moves to nth line from top
'
,
()
=>
{
let
viewModelHelper
=
aViewModelHelper
(
thisModel
);
viewModelHelper
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
10
,
1
);
thisCursor
=
aCursor
(
viewModelHelper
);
thisViewModel
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
10
,
1
);
moveTo
(
thisCursor
,
4
,
1
);
moveToTop
(
thisCursor
,
3
);
...
...
@@ -388,9 +355,7 @@ suite('Cursor move command test', () => {
});
test
(
'
move to view top line moves to last line if n is greater than last visible line number
'
,
()
=>
{
let
viewModelHelper
=
aViewModelHelper
(
thisModel
);
viewModelHelper
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
3
,
1
);
thisCursor
=
aCursor
(
viewModelHelper
);
thisViewModel
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
3
,
1
);
moveTo
(
thisCursor
,
2
,
2
);
moveToTop
(
thisCursor
,
4
);
...
...
@@ -399,9 +364,7 @@ suite('Cursor move command test', () => {
});
test
(
'
move to view center line moves to the center line
'
,
()
=>
{
let
viewModelHelper
=
aViewModelHelper
(
thisModel
);
viewModelHelper
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
3
,
1
,
3
,
1
);
thisCursor
=
aCursor
(
viewModelHelper
);
thisViewModel
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
3
,
1
,
3
,
1
);
moveTo
(
thisCursor
,
2
,
2
);
moveToCenter
(
thisCursor
);
...
...
@@ -410,9 +373,7 @@ suite('Cursor move command test', () => {
});
test
(
'
move to view bottom line moves to last visible line if it is last line
'
,
()
=>
{
let
viewModelHelper
=
aViewModelHelper
(
thisModel
);
viewModelHelper
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
5
,
1
);
thisCursor
=
aCursor
(
viewModelHelper
);
thisViewModel
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
5
,
1
);
moveTo
(
thisCursor
,
2
,
2
);
moveToBottom
(
thisCursor
);
...
...
@@ -421,9 +382,7 @@ suite('Cursor move command test', () => {
});
test
(
'
move to view bottom line moves to last visible line when last line is not visible
'
,
()
=>
{
let
viewModelHelper
=
aViewModelHelper
(
thisModel
);
viewModelHelper
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
2
,
1
,
3
,
1
);
thisCursor
=
aCursor
(
viewModelHelper
);
thisViewModel
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
2
,
1
,
3
,
1
);
moveTo
(
thisCursor
,
2
,
2
);
moveToBottom
(
thisCursor
);
...
...
@@ -432,9 +391,7 @@ suite('Cursor move command test', () => {
});
test
(
'
move to view bottom line moves to nth line from bottom
'
,
()
=>
{
let
viewModelHelper
=
aViewModelHelper
(
thisModel
);
viewModelHelper
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
5
,
1
);
thisCursor
=
aCursor
(
viewModelHelper
);
thisViewModel
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
1
,
1
,
5
,
1
);
moveTo
(
thisCursor
,
4
,
1
);
moveToBottom
(
thisCursor
,
3
);
...
...
@@ -443,20 +400,13 @@ suite('Cursor move command test', () => {
});
test
(
'
move to view bottom line moves to first line if n is lesser than first visible line number
'
,
()
=>
{
let
viewModelHelper
=
aViewModelHelper
(
thisModel
);
viewModelHelper
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
2
,
1
,
5
,
1
);
thisCursor
=
aCursor
(
viewModelHelper
);
thisViewModel
.
getCompletelyVisibleViewRange
=
()
=>
new
Range
(
2
,
1
,
5
,
1
);
moveTo
(
thisCursor
,
4
,
1
);
moveToBottom
(
thisCursor
,
5
);
cursorEqual
(
thisCursor
,
2
,
2
);
});
function
aCursor
(
viewModelHelper
?:
IViewModelHelper
):
Cursor
{
return
new
Cursor
(
thisConfiguration
,
thisModel
,
viewModelHelper
||
aViewModelHelper
(
thisModel
));
}
});
interface
ICursorOpts
{
...
...
src/vs/editor/test/common/editorTestUtils.ts
浏览文件 @
dcbe78a1
...
...
@@ -5,59 +5,9 @@
'
use strict
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
IModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IViewModelHelper
}
from
'
vs/editor/common/controller/cursorCommon
'
;
export
function
withEditorModel
(
text
:
string
[],
callback
:
(
model
:
Model
)
=>
void
):
void
{
var
model
=
Model
.
createFromString
(
text
.
join
(
'
\n
'
));
callback
(
model
);
model
.
dispose
();
}
export
function
viewModelHelper
(
model
:
IModel
):
IViewModelHelper
{
return
{
viewModel
:
model
,
coordinatesConverter
:
{
convertViewPositionToModelPosition
:
(
viewPosition
:
Position
):
Position
=>
{
return
viewPosition
;
},
convertViewRangeToModelRange
:
(
viewRange
:
Range
):
Range
=>
{
return
viewRange
;
},
convertViewSelectionToModelSelection
:
(
viewSelection
:
Selection
):
Selection
=>
{
return
viewSelection
;
},
validateViewPosition
:
(
viewPosition
:
Position
,
expectedModelPosition
:
Position
):
Position
=>
{
return
expectedModelPosition
;
},
validateViewRange
:
(
viewRange
:
Range
,
modelRange
:
Range
):
Range
=>
{
return
modelRange
;
},
convertModelPositionToViewPosition
:
(
modelPosition
:
Position
):
Position
=>
{
return
modelPosition
;
},
convertModelRangeToViewRange
:
(
modelRange
:
Range
):
Range
=>
{
return
modelRange
;
},
convertModelSelectionToViewSelection
:
(
modelSelection
:
Selection
):
Selection
=>
{
return
modelSelection
;
},
modelPositionIsVisible
:
(
modelPosition
:
Position
):
boolean
=>
{
return
true
;
},
},
getScrollTop
:
():
number
=>
0
,
getCompletelyVisibleViewRange
:
()
=>
null
,
getCompletelyVisibleViewRangeAtScrollTop
:
(
scrollTop
:
number
)
=>
null
,
getVerticalOffsetForViewLineNumber
:
(
viewLineNumber
:
number
)
=>
0
};
}
src/vs/editor/test/common/mocks/mockCodeEditor.ts
浏览文件 @
dcbe78a1
...
...
@@ -71,12 +71,31 @@ export interface MockCodeEditorCreationOptions extends editorOptions.IEditorOpti
}
export
function
withMockCodeEditor
(
text
:
string
[],
options
:
MockCodeEditorCreationOptions
,
callback
:
(
editor
:
MockCodeEditor
,
cursor
:
Cursor
)
=>
void
):
void
{
let
editor
=
<
MockCodeEditor
>
mockCodeEditor
(
text
,
options
);
// create a model if necessary and remember it in order to dispose it.
let
modelToDispose
:
Model
=
null
;
if
(
!
options
.
model
)
{
modelToDispose
=
Model
.
createFromString
(
text
.
join
(
'
\n
'
));
options
.
model
=
modelToDispose
;
}
let
editor
=
<
MockCodeEditor
>
_mockCodeEditor
(
options
);
callback
(
editor
,
editor
.
getCursor
());
if
(
modelToDispose
)
{
modelToDispose
.
dispose
();
}
editor
.
dispose
();
}
export
function
mockCodeEditor
(
text
:
string
[],
options
:
MockCodeEditorCreationOptions
):
CommonCodeEditor
{
// TODO: who owns this model now?
if
(
!
options
.
model
)
{
options
.
model
=
Model
.
createFromString
(
text
.
join
(
'
\n
'
));
}
return
_mockCodeEditor
(
options
);
}
function
_mockCodeEditor
(
options
:
MockCodeEditorCreationOptions
):
CommonCodeEditor
{
let
contextKeyService
=
new
MockContextKeyService
();
...
...
@@ -85,10 +104,6 @@ export function mockCodeEditor(text: string[], options: MockCodeEditorCreationOp
let
instantiationService
=
new
InstantiationService
(
services
);
let
editor
=
new
MockCodeEditor
(
new
MockScopeLocation
(),
options
,
instantiationService
,
contextKeyService
);
let
model
=
options
.
model
||
Model
.
createFromString
(
text
.
join
(
'
\n
'
));
if
(
model
)
{
editor
.
setModel
(
model
);
}
editor
.
setModel
(
options
.
model
);
return
editor
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录