Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
21a81d08
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,发现更多精彩内容 >>
提交
21a81d08
编写于
7月 26, 2017
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
introduce modes.IColor
上级
b275fc78
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
122 addition
and
33 deletion
+122
-33
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+54
-8
src/vs/editor/contrib/colorPicker/browser/colorPicker.ts
src/vs/editor/contrib/colorPicker/browser/colorPicker.ts
+2
-2
src/vs/editor/contrib/colorPicker/common/color.ts
src/vs/editor/contrib/colorPicker/common/color.ts
+2
-3
src/vs/editor/contrib/colorPicker/common/colorPicker.ts
src/vs/editor/contrib/colorPicker/common/colorPicker.ts
+4
-4
src/vs/editor/contrib/hover/browser/modesContentHover.ts
src/vs/editor/contrib/hover/browser/modesContentHover.ts
+8
-5
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+41
-7
src/vs/workbench/api/electron-browser/mainThreadLanguageFeatures.ts
...kbench/api/electron-browser/mainThreadLanguageFeatures.ts
+11
-4
未找到文件。
src/vs/editor/common/modes.ts
浏览文件 @
21a81d08
...
...
@@ -653,21 +653,67 @@ export interface LinkProvider {
}
/**
* A color in
side the editor
.
* A color in
RGBA format
.
*/
export
interface
IColor
{
/**
* The red component in the range [0-1].
*/
readonly
red
:
number
;
/**
* The green component in the range [0-1].
*/
readonly
green
:
number
;
/**
* The blue component in the range [0-1].
*/
readonly
blue
:
number
;
/**
* The alpha component in the range [0-1].
*/
readonly
alpha
:
number
;
}
// TODO@joao TODO@michel can we use a formatter here?
export
type
IColorFormat
=
string
|
{
opaque
:
string
,
transparent
:
string
};
export
interface
IColorInfo
{
color
:
Color
;
/**
* A color range is a range in a text model which represents a color.
*/
export
interface
IColorRange
{
/**
* The range within the model.
*/
range
:
IRange
;
/**
* The color represented in this range.
*/
color
:
IColor
;
// TODO@joao TODO@michel can we drop this?
format
:
IColorFormat
;
/**
* The available formats for this specific color.
*/
availableFormats
:
IColorFormat
[];
range
:
IRange
;
}
/**
* A provider of colors.
* A provider of colors
for editor models
.
*/
export
interface
ColorProvider
{
export
interface
Color
Range
Provider
{
provideColors
(
model
:
editorCommon
.
IReadOnlyModel
,
token
:
CancellationToken
):
IColorInfo
[]
|
Thenable
<
IColorInfo
[]
>
;
/**
* Provides the color ranges for a specific model.
*/
provideColorRanges
(
model
:
editorCommon
.
IReadOnlyModel
,
token
:
CancellationToken
):
IColorRange
[]
|
Thenable
<
IColorRange
[]
>
;
}
export
interface
IResourceEdit
{
...
...
@@ -786,7 +832,7 @@ export const LinkProviderRegistry = new LanguageFeatureRegistry<LinkProvider>();
/**
* @internal
*/
export
const
ColorProviderRegistry
=
new
LanguageFeatureRegistry
<
ColorProvider
>
();
export
const
ColorProviderRegistry
=
new
LanguageFeatureRegistry
<
Color
Range
Provider
>
();
/**
* @internal
...
...
src/vs/editor/contrib/colorPicker/browser/colorPicker.ts
浏览文件 @
21a81d08
...
...
@@ -9,7 +9,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
registerThemingParticipant
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
editorWidgetBackground
,
editorWidgetBorder
}
from
'
vs/platform/theme/common/colorRegistry
'
;
import
{
ColorProviderRegistry
,
IColor
Info
}
from
'
vs/editor/common/modes
'
;
import
{
ColorProviderRegistry
,
IColor
Range
}
from
'
vs/editor/common/modes
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
getColors
}
from
'
vs/editor/contrib/colorPicker/common/colorPicker
'
;
import
{
IRange
}
from
'
vs/editor/common/core/range
'
;
...
...
@@ -100,7 +100,7 @@ export class ColorPicker implements IEditorContribution {
}
}
private
updateDecorations
(
colorInfos
:
IColor
Info
[]):
void
{
private
updateDecorations
(
colorInfos
:
IColor
Range
[]):
void
{
this
.
editor
.
changeDecorations
((
changeAccessor
:
IModelDecorationsChangeAccessor
)
=>
{
let
newDecorations
:
IModelDeltaDecoration
[]
=
[];
...
...
src/vs/editor/contrib/colorPicker/common/color.ts
浏览文件 @
21a81d08
...
...
@@ -3,11 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
IColorFormat
}
from
'
vs/editor/common/modes
'
;
import
{
Color
}
from
'
vs/base/common/color
'
;
import
{
IColor
,
IColorFormat
}
from
'
vs/editor/common/modes
'
;
export
interface
IColorDecorationExtraOptions
{
readonly
color
:
Color
;
readonly
color
:
I
Color
;
readonly
format
:
IColorFormat
;
readonly
availableFormats
:
IColorFormat
[];
}
...
...
src/vs/editor/contrib/colorPicker/common/colorPicker.ts
浏览文件 @
21a81d08
...
...
@@ -4,17 +4,17 @@
*--------------------------------------------------------------------------------------------*/
import
{
TPromise
}
from
"
vs/base/common/winjs.base
"
;
import
{
ColorProviderRegistry
,
IColor
Info
}
from
"
vs/editor/common/modes
"
;
import
{
ColorProviderRegistry
,
IColor
Range
}
from
"
vs/editor/common/modes
"
;
import
{
asWinJsPromise
}
from
"
vs/base/common/async
"
;
import
{
onUnexpectedExternalError
}
from
"
vs/base/common/errors
"
;
import
{
IReadOnlyModel
}
from
"
vs/editor/common/editorCommon
"
;
export
function
getColors
(
model
:
IReadOnlyModel
):
TPromise
<
IColor
Info
[]
>
{
let
colorInfo
:
IColor
Info
[]
=
[];
export
function
getColors
(
model
:
IReadOnlyModel
):
TPromise
<
IColor
Range
[]
>
{
let
colorInfo
:
IColor
Range
[]
=
[];
// ask all providers for colors in parallel
const
promises
=
ColorProviderRegistry
.
ordered
(
model
).
reverse
().
map
(
provider
=>
{
return
asWinJsPromise
(
token
=>
provider
.
provideColors
(
model
,
token
)).
then
(
result
=>
{
return
asWinJsPromise
(
token
=>
provider
.
provideColor
Range
s
(
model
,
token
)).
then
(
result
=>
{
if
(
Array
.
isArray
(
result
))
{
colorInfo
=
colorInfo
.
concat
(
result
);
}
...
...
src/vs/editor/contrib/hover/browser/modesContentHover.ts
浏览文件 @
21a81d08
...
...
@@ -14,7 +14,7 @@ import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/ope
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IRange
,
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
HoverProviderRegistry
,
Hover
,
IColorFormat
}
from
'
vs/editor/common/modes
'
;
import
{
HoverProviderRegistry
,
Hover
,
IColor
,
IColor
Format
}
from
'
vs/editor/common/modes
'
;
import
{
tokenizeToString
}
from
'
vs/editor/common/modes/textToHtmlTokenizer
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
getHover
}
from
'
../common/hover
'
;
...
...
@@ -26,13 +26,13 @@ import { ColorPickerModel } from "vs/editor/contrib/colorPicker/browser/colorPic
import
{
ColorPickerWidget
}
from
"
vs/editor/contrib/colorPicker/browser/colorPickerWidget
"
;
import
{
isColorDecorationOptions
}
from
'
vs/editor/contrib/colorPicker/common/color
'
;
import
{
ColorFormatter
}
from
'
vs/editor/contrib/colorPicker/common/colorFormatter
'
;
import
{
Color
}
from
'
vs/base/common/color
'
;
import
{
Color
,
RGBA
}
from
'
vs/base/common/color
'
;
class
ColorHover
{
constructor
(
public
readonly
range
:
IRange
,
public
readonly
color
:
Color
,
public
readonly
color
:
I
Color
,
public
readonly
format
:
IColorFormat
,
public
readonly
availableFormats
:
IColorFormat
[]
)
{
}
...
...
@@ -103,7 +103,6 @@ class ModesContentComputer implements IHoverComputer<HoverPart[]> {
const
extraOptions
=
options
&&
options
.
extraOptions
;
if
(
isColorDecorationOptions
(
extraOptions
))
{
console
.
log
(
'
found color!
'
);
const
{
color
,
format
,
availableFormats
}
=
extraOptions
;
return
new
ColorHover
(
range
,
color
,
format
,
availableFormats
);
}
else
{
...
...
@@ -339,7 +338,11 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
});
}
const
model
=
new
ColorPickerModel
(
msg
.
color
.
toRGBA
().
toString
(),
msg
.
color
,
opaqueFormatter
,
transparentFormatter
,
availableFormatters
,
this
.
_editor
.
getModel
(),
msg
.
range
);
const
{
red
,
green
,
blue
,
alpha
}
=
msg
.
color
;
const
rgba
=
new
RGBA
(
red
*
255
,
green
*
255
,
blue
*
255
,
alpha
*
255
);
const
color
=
Color
.
fromRGBA
(
rgba
);
const
model
=
new
ColorPickerModel
(
rgba
.
toString
(),
color
,
opaqueFormatter
,
transparentFormatter
,
availableFormatters
,
this
.
_editor
.
getModel
(),
msg
.
range
);
const
widget
=
this
.
_register
(
new
ColorPickerWidget
(
model
,
this
.
_editor
));
model
.
widget
=
widget
;
...
...
src/vs/monaco.d.ts
浏览文件 @
21a81d08
...
...
@@ -4788,25 +4788,59 @@ declare module monaco.languages {
}
/**
* A color in
side the editor
.
* A color in
RGBA format
.
*/
export
interface
IColor
{
/**
* The red component in the range [0-1].
*/
readonly
red
:
number
;
/**
* The green component in the range [0-1].
*/
readonly
green
:
number
;
/**
* The blue component in the range [0-1].
*/
readonly
blue
:
number
;
/**
* The alpha component in the range [0-1].
*/
readonly
alpha
:
number
;
}
export
type
IColorFormat
=
string
|
{
opaque
:
string
;
transparent
:
string
;
};
export
interface
IColorInfo
{
color
:
Color
;
/**
* A color range is a range in a text model which represents a color.
*/
export
interface
IColorRange
{
/**
* The range within the model.
*/
range
:
IRange
;
/**
* The color represented in this range.
*/
color
:
IColor
;
format
:
IColorFormat
;
/**
* The available formats used in the model to stringify the color.
*/
availableFormats
:
IColorFormat
[];
range
:
IRange
;
}
/**
* A provider of colors.
* A provider of colors
for editor models
.
*/
export
interface
ColorProvider
{
provideColors
(
model
:
editor
.
IReadOnlyModel
,
token
:
CancellationToken
):
IColorInfo
[]
|
Thenable
<
IColorInfo
[]
>
;
export
interface
ColorRangeProvider
{
/**
* Provides the color ranges for a specific model.
*/
provideColorRanges
(
model
:
editor
.
IReadOnlyModel
,
token
:
CancellationToken
):
IColorRange
[]
|
Thenable
<
IColorRange
[]
>
;
}
export
interface
IResourceEdit
{
...
...
src/vs/workbench/api/electron-browser/mainThreadLanguageFeatures.ts
浏览文件 @
21a81d08
...
...
@@ -21,7 +21,6 @@ import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageCo
import
{
LanguageConfiguration
}
from
'
vs/editor/common/modes/languageConfiguration
'
;
import
{
IHeapService
}
from
'
./mainThreadHeapService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
Color
,
RGBA
}
from
"
vs/base/common/color
"
;
export
class
MainThreadLanguageFeatures
extends
MainThreadLanguageFeaturesShape
{
...
...
@@ -270,8 +269,8 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape
$registerDocumentColorProvider
(
handle
:
number
,
selector
:
vscode
.
DocumentSelector
):
TPromise
<
any
>
{
const
proxy
=
this
.
_proxy
;
this
.
_registrations
[
handle
]
=
modes
.
ColorProviderRegistry
.
register
(
selector
,
<
modes
.
ColorProvider
>
{
provideColors
:
function
(
model
,
token
)
{
this
.
_registrations
[
handle
]
=
modes
.
ColorProviderRegistry
.
register
(
selector
,
<
modes
.
Color
Range
Provider
>
{
provideColor
Range
s
:
function
(
model
,
token
)
{
const
provider
=
this
;
return
wireCancellationToken
(
token
,
proxy
.
$provideDocumentColors
(
handle
,
model
.
uri
))
.
then
((
colorInfos
)
=>
{
...
...
@@ -294,8 +293,16 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape
}
});
const
[
red
,
green
,
blue
,
alpha
]
=
c
.
color
;
const
color
=
{
red
:
red
/
255.0
,
green
:
green
/
255.0
,
blue
:
blue
/
255.0
,
alpha
};
return
{
color
:
Color
.
fromRGBA
(
new
RGBA
(
c
.
color
[
0
],
c
.
color
[
1
],
c
.
color
[
2
],
c
.
color
[
3
]
*
255
))
,
color
,
format
:
format
,
availableFormats
:
availableFormats
,
range
:
c
.
range
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录