提交 44b8ebe0 编写于 作者: J Johannes Rieken

merge with master

......@@ -57,7 +57,7 @@
},
{
"name": "electron",
"version": "0.35.5",
"version": "0.35.6",
"license": "MIT",
"repositoryURL": "https://github.com/atom/electron",
"isProd": true
......
environment:
ELECTRON_RUN_AS_NODE: 1
ATOM_SHELL_INTERNAL_RUN_AS_NODE: 1
install:
- ps: Install-Product node 4.1.1 x64
......
......@@ -10,7 +10,7 @@
<key>name</key>
<string>keyword.command.dosbatch</string>
<key>match</key>
<string>\b(?i)(?:append|assoc|at|attrib|break|cacls|cd|chcp|chdir|chkdsk|chkntfs|cls|cmd|color|comp|compact|convert|copy|date|del|dir|diskcomp|diskcopy|doskey|echo|endlocal|erase|fc|find|findstr|format|ftype|graftabl|help|keyb|label|md|mkdir|mode|more|move|path|pause|popd|print|prompt|pushd|rd|recover|rem|ren|rename|replace|restore|rmdir|set|setlocal|shift|sort|start|subst|time|title|tree|type|ver|verify|vol|xcopy)\b</string>
<string>\b(?i)(?:append|assoc|at|attrib|break|cacls|cd|chcp|chdir|chkdsk|chkntfs|cls|cmd|color|comp|compact|convert|copy|date|del|dir|diskcomp|diskcopy|doskey|echo|endlocal|erase|fc|find|findstr|format|ftype|graftabl|help|keyb|label|md|mkdir|mode|more|move|path|pause|popd|print|prompt|pushd|rd|recover|ren|rename|replace|restore|rmdir|set|setlocal|shift|sort|start|subst|time|title|tree|type|ver|verify|vol|xcopy)\b</string>
</dict>
<dict>
<key>name</key>
......@@ -54,7 +54,7 @@
<key>name</key>
<string>comment.line.rem.dosbatch</string>
<key>match</key>
<string>(?:^|\s)((?i)rem)(?:$|\s.*$)</string>
<string>\b((?i)rem)(?:$|\s.*$)</string>
</dict>
<dict>
<key>name</key>
......@@ -62,6 +62,72 @@
<key>match</key>
<string>\s*:\s*:.*$</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>variable.parameter.function.begin.shell</string>
</dict>
</dict>
<key>name</key>
<string>variable.parameter.function.dosbatch</string>
<key>match</key>
<string>(?i)(%)(~(?:f|d|p|n|x|s|a|t|z|\$[^:]*:)*)?\d</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>variable.parameter.loop.begin.shell</string>
</dict>
</dict>
<key>name</key>
<string>variable.parameter.loop.dosbatch</string>
<key>match</key>
<string>(?i)(%%)(~(?:f|d|p|n|x|s|a|t|z|\$[^:]*:)*)?[a-z]</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>variable.other.parsetime.begin.shell</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>variable.other.parsetime.end.shell</string>
</dict>
</dict>
<key>name</key>
<string>variable.other.parsetime.dosbatch</string>
<key>match</key>
<string>(%)[^%]+(%)</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>variable.other.delayed.begin.shell</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>variable.other.delayed.end.shell</string>
</dict>
</dict>
<key>name</key>
<string>variable.other.delayed.dosbatch</string>
<key>match</key>
<string>(!)[^!]+(!)</string>
</dict>
<dict>
<key>begin</key>
<string>"</string>
......@@ -84,7 +150,7 @@
<key>name</key>
<string>string.quoted.double.dosbatch</string>
<key>end</key>
<string>"</string>
<string>"|$</string>
</dict>
<dict>
<key>name</key>
......
{
"account": "monacobuild",
"container": "debuggers",
"zip": "b5b96dd/node-debug.zip",
"zip": "beaf9dc/node-debug.zip",
"output": ""
}
......@@ -3,7 +3,7 @@
"displayName": "Colorful Default Themes - Please provide feedback in issue 1849",
"description": "The default VS Code Light and Dark themes with a touch of color. We are considering adding these to the default themes in the January release. Please provide feedback in issue 1849.",
"categories": [ "Themes" ],
"version": "0.1.5",
"version": "0.1.6",
"publisher": "aeschli",
"engines": { "vscode": "*" },
"contributes": {
......
......@@ -10,7 +10,7 @@
<key>name</key>
<string>Function declarations</string>
<key>scope</key>
<string>entity.name.function</string>
<string>entity.name.function, entity.method.name</string>
<key>settings</key>
<dict>
<key>foreground</key>
......@@ -21,7 +21,7 @@
<key>name</key>
<string>Types declaration and references</string>
<key>scope</key>
<string>meta.parameter.type, entity.name.class, new.storage.type, meta.cast, cast.storage.type, heritage.storage.type, annotation.storage.type, var.annotation.storage.type</string>
<string>meta.parameter.type, name.class, storage.type.cs, return-type, new.storage.type, meta.cast, cast.storage.type, heritage.storage.type, annotation.storage.type, var.annotation.storage.type</string>
<key>settings</key>
<dict>
<key>foreground</key>
......
......@@ -10,7 +10,7 @@
<key>name</key>
<string>Function declarations</string>
<key>scope</key>
<string>entity.name.function</string>
<string>entity.name.function, entity.method.name</string>
<key>settings</key>
<dict>
<key>foreground</key>
......@@ -21,7 +21,7 @@
<key>name</key>
<string>Types declaration and references</string>
<key>scope</key>
<string>meta.parameter.type, entity.name.class, new.storage.type, meta.cast, cast.storage.type, heritage.storage.type, annotation.storage.type, var.annotation.storage.type</string>
<string>meta.parameter.type, name.class, storage.type.cs, return-type, new.storage.type, meta.cast, cast.storage.type, heritage.storage.type, annotation.storage.type, var.annotation.storage.type</string> <key>settings</key>
<key>settings</key>
<dict>
<key>foreground</key>
......
......@@ -100,7 +100,7 @@ function registerSupports(modeID: string, host: TypeScriptServiceClientHost, cli
},
{
// e.g. * ...|
beforeText: /^(\t|(\ \ ))*\ \*\ ([^\*]|\*(?!\/))*$/,
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
action: { indentAction: IndentAction.None, appendText: '* ' }
},
{
......
......@@ -47,7 +47,7 @@ function generatePatchedEnv(env:any, stdInPipeName:string, stdOutPipeName:string
newEnv['STDIN_PIPE_NAME'] = stdInPipeName;
newEnv['STDOUT_PIPE_NAME'] = stdOutPipeName;
newEnv['ELECTRON_RUN_AS_NODE'] = '1';
newEnv['ATOM_SHELL_INTERNAL_RUN_AS_NODE'] = '1';
return newEnv;
}
......
......@@ -31,7 +31,7 @@ var stdOutPipeName = process.env['STDOUT_PIPE_NAME'];
log('STDIN_PIPE_NAME: ' + stdInPipeName);
log('STDOUT_PIPE_NAME: ' + stdOutPipeName);
log('ELECTRON_RUN_AS_NODE: ' + process.env['ELECTRON_RUN_AS_NODE']);
log('ATOM_SHELL_INTERNAL_RUN_AS_NODE: ' + process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE']);
// stdout redirection to named pipe
(function() {
......@@ -136,7 +136,7 @@ log('ELECTRON_RUN_AS_NODE: ' + process.env['ELECTRON_RUN_AS_NODE']);
// Unset the custom environmental variables that should not get inherited
delete process.env['STDIN_PIPE_NAME'];
delete process.env['STDOUT_PIPE_NAME'];
delete process.env['ELECTRON_RUN_AS_NODE'];
delete process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
require(program);
......
......@@ -9,7 +9,8 @@
},
"scripts": {
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../gulpfile.plugins.js compile-plugin:vscode-api-tests ./tsconfig.json"
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../gulpfile.plugins.js compile-plugin:vscode-api-tests ./tsconfig.json",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"typescript": "^1.6.2",
......
{
"name": "Code",
"version": "0.10.6",
"electronVersion": "0.35.5",
"electronVersion": "0.35.6",
"author": {
"name": "Microsoft Corporation"
},
......
@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
set ATOM_SHELL_INTERNAL_RUN_AS_NODE=1
"%~dp0..\\Code.exe" "%~dp0code.js" %*
endlocal
\ No newline at end of file
delete process.env['ELECTRON_RUN_AS_NODE'];
delete process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
require('child_process').spawn(require('path').resolve(__dirname, '..', 'Code.exe'), process.argv.slice(2), { detached: true, stdio: 'ignore' });
process.exit(0);
\ No newline at end of file
@echo off
set ELECTRON_RUN_AS_NODE=1
set ATOM_SHELL_INTERNAL_RUN_AS_NODE=1
pushd %~dp0\..
.\.build\electron\Code.exe .\node_modules\mocha\bin\_mocha %*
......
......@@ -9,11 +9,11 @@ fi
# Unit Tests
if [[ "$OSTYPE" == "darwin"* ]]; then
cd $ROOT ; ulimit -n 4096 ; ELECTRON_RUN_AS_NODE=1 \
cd $ROOT ; ulimit -n 4096 ; ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 \
./.build/electron/Electron.app/Contents/MacOS/Electron \
node_modules/mocha/bin/_mocha $*
else
cd $ROOT ; ELECTRON_RUN_AS_NODE=1 \
cd $ROOT ; ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 \
./.build/electron/electron \
node_modules/mocha/bin/_mocha $*
fi
......
......@@ -919,8 +919,13 @@ export var EventType = {
ANIMATION_ITERATION: Browser.isWebKit ? 'webkitAnimationIteration' : 'animationiteration'
};
export interface EventLike {
preventDefault(): void;
stopPropagation(): void;
}
export var EventHelper = {
stop: function (e:Event, cancelBubble?:boolean) {
stop: function (e:EventLike, cancelBubble?:boolean) {
if (e.preventDefault) {
e.preventDefault();
} else {
......@@ -933,7 +938,7 @@ export var EventHelper = {
e.stopPropagation();
} else {
// IE8
e.cancelBubble = true;
(<any>e).cancelBubble = true;
}
}
}
......@@ -1068,10 +1073,14 @@ export function emmet(description: string):HTMLElement {
return result;
};
export function show(element: HTMLElement): void {
element.style.display = null;
export function show(...elements: HTMLElement[]): void {
for (const element of elements) {
element.style.display = null;
}
}
export function hide(element: HTMLElement): void {
element.style.display = 'none';
export function hide(...elements: HTMLElement[]): void {
for (const element of elements) {
element.style.display = 'none';
}
}
......@@ -6,77 +6,78 @@
'use strict';
import 'vs/css!./checkbox';
import nls = require('vs/nls');
import Builder = require('vs/base/browser/builder');
import mouse = require('vs/base/browser/mouseEvent');
import keyboard = require('vs/base/browser/keyboardEvent');
import * as nls from 'vs/nls';
import {KeyCode} from 'vs/base/common/keyCodes';
import {Widget} from 'vs/base/browser/ui/widget';
import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
var $ = Builder.$;
export interface ICheckboxOpts {
actionClassName: string;
title: string;
isChecked: boolean;
onChange: () => void;
onKeyDown?: (e:StandardKeyboardEvent) => void;
}
export class Checkbox {
export class Checkbox extends Widget {
private actionClassName: string;
private title: string;
public isChecked: boolean;
private onChange: () => void;
private listenersToRemove: { (): void; }[];
private _opts: ICheckboxOpts;
public domNode: HTMLElement;
constructor(actionClassName: string, title: string, isChecked: boolean, onChange: () => void) {
this.actionClassName = actionClassName;
this.title = title;
this.isChecked = isChecked;
this.onChange = onChange;
private _checked: boolean;
this.listenersToRemove = [];
constructor(opts:ICheckboxOpts) {
super();
this._opts = opts;
this._checked = this._opts.isChecked;
this.domNode = document.createElement('div');
this.domNode.title = title;
this.render();
$(this.domNode).attr({
'aria-checked': 'false',
'aria-label': this.title,
'tabindex': 0,
'role': 'checkbox'
});
$(this.domNode).on('click', (e: MouseEvent) => {
var ev = new mouse.StandardMouseEvent(e);
this.isChecked = !this.isChecked;
this.render();
this.onChange();
this.domNode.title = this._opts.title;
this.domNode.className = this._className();
this.domNode.tabIndex = 0;
this.domNode.setAttribute('role', 'checkbox');
this.domNode.setAttribute('aria-checked', String(this._checked));
this.domNode.setAttribute('aria-label', this._opts.title);
this.onclick(this.domNode, (ev) => {
this._checked = !this._checked;
this.domNode.className = this._className();
this._opts.onChange();
ev.preventDefault();
}, this.listenersToRemove);
});
$(this.domNode).on('keydown', (browserEvent: KeyboardEvent) => {
var keyboardEvent = new keyboard.StandardKeyboardEvent(browserEvent);
this.onkeydown(this.domNode, (keyboardEvent) => {
if (keyboardEvent.keyCode === KeyCode.Space || keyboardEvent.keyCode === KeyCode.Enter) {
this.isChecked = !this.isChecked;
this.render();
this.onChange();
this._checked = !this._checked;
this.domNode.className = this._className();
this._opts.onChange();
keyboardEvent.preventDefault();
return;
}
}, this.listenersToRemove);
if (this._opts.onKeyDown) {
this._opts.onKeyDown(keyboardEvent);
}
});
}
public focus(): void {
this.domNode.focus();
}
private render(): void {
this.domNode.className = this.className();
public get checked(): boolean {
return this._checked;
}
public setChecked(newIsChecked: boolean): void {
this.isChecked = newIsChecked;
$(this.domNode).attr('aria-checked', this.isChecked);
this.render();
public set checked(newIsChecked:boolean) {
this._checked = newIsChecked;
this.domNode.setAttribute('aria-checked', String(this._checked));
this.domNode.className = this._className();
}
private className(): string {
return 'custom-checkbox ' + this.actionClassName + ' ' + (this.isChecked ? 'checked' : 'unchecked');
private _className(): string {
return 'custom-checkbox ' + this._opts.actionClassName + ' ' + (this._checked ? 'checked' : 'unchecked');
}
public width(): number {
......@@ -85,16 +86,11 @@ export class Checkbox {
public enable(): void {
this.domNode.tabIndex = 0;
this.domNode.setAttribute('aria-disabled', String(false));
}
public disable(): void {
this.domNode.tabIndex = -1;
this.domNode.setAttribute('aria-disabled', String(true));
}
public destroy(): void {
this.listenersToRemove.forEach((element) => {
element();
});
this.listenersToRemove = [];
}
}
\ No newline at end of file
}
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
.monaco-count-badge {
padding: 0.2em 0.4em;
padding: 0.2em 0.5em;
border-radius: 1em;
font-size: 85%;
font-weight: normal;
......
......@@ -33,6 +33,28 @@
right: 2px;
}
.monaco-findInput > .controls > .matchCount {
margin-left: 2px;
float: left;
overflow: hidden;
max-width: 30px;
min-width: 20px;
text-align: center;
border-radius: 5px;
padding: 0 4px;
-webkit-box-sizing: border-box;
-o-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.vs .monaco-findInput > .controls > .matchCount {
background: #ddd;
}
.vs .monaco-findInput > .controls > .custom-checkbox.case-sensitive {
background: url('case-sensitive.svg') center center no-repeat;
}
......@@ -54,6 +76,10 @@
background-color: #333;
}
.vs-dark .monaco-findInput > .controls > .matchCount {
background: #555;
}
.vs-dark .monaco-findInput > .controls > .custom-checkbox.case-sensitive {
background: url('case-sensitive-dark.svg') center center no-repeat;
}
......
......@@ -5,20 +5,21 @@
'use strict';
import 'vs/css!./findInput';
import nls = require('vs/nls');
import Builder = require('vs/base/browser/builder');
import mouse = require('vs/base/browser/mouseEvent');
import keyboard = require('vs/base/browser/keyboardEvent');
import InputBox = require('vs/base/browser/ui/inputbox/inputBox');
import Checkbox = require('vs/base/browser/ui/checkbox/checkbox');
import ContextView = require('vs/base/browser/ui/contextview/contextview');
var $ = Builder.$;
export interface IOptions {
import * as nls from 'vs/nls';
import * as dom from 'vs/base/browser/dom';
import {IMessage as InputBoxMessage, IInputValidator, InputBox} from 'vs/base/browser/ui/inputbox/inputBox';
import {Checkbox} from 'vs/base/browser/ui/checkbox/checkbox';
import {IContextViewProvider} from 'vs/base/browser/ui/contextview/contextview';
import {Widget} from 'vs/base/browser/ui/widget';
import Event, {Emitter} from 'vs/base/common/event';
import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {StandardMouseEvent} from 'vs/base/browser/mouseEvent';
export interface IFindInputOptions {
placeholder?:string;
width?:number;
validation?:InputBox.IInputValidator;
validation?:IInputValidator;
label:string;
appendCaseSensitiveLabel?: string;
......@@ -26,78 +27,72 @@ export interface IOptions {
appendRegexLabel?: string;
}
export interface IMatchCountState {
count: string;
isVisible: boolean;
title: string;
}
const NLS_REGEX_CHECKBOX_LABEL = nls.localize('regexDescription', "Use Regular Expression");
const NLS_WHOLE_WORD_CHECKBOX_LABEL = nls.localize('wordsDescription', "Match Whole Word");
const NLS_CASE_SENSITIVE_CHECKBOX_LABEL = nls.localize('caseDescription', "Match Case");
const NLS_DEFAULT_LABEL = nls.localize('defaultLabel', "input");
export class FindInput {
export class FindInput extends Widget {
static OPTION_CHANGE:string = 'optionChange';
private contextViewProvider: ContextView.IContextViewProvider;
private onOptionChange:(event:Event)=>void;
private contextViewProvider: IContextViewProvider;
private width:number;
private placeholder:string;
private validation:InputBox.IInputValidator;
private validation:IInputValidator;
private label:string;
private listenersToRemove:{():void;}[];
private regex:Checkbox.Checkbox;
private wholeWords:Checkbox.Checkbox;
private caseSensitive:Checkbox.Checkbox;
private regex:Checkbox;
private wholeWords:Checkbox;
private caseSensitive:Checkbox;
private matchCount: MatchCount;
public domNode: HTMLElement;
public validationNode: Builder.Builder;
public inputBox:InputBox.InputBox;
public inputBox:InputBox;
private _onDidOptionChange = this._register(new Emitter<void>());
public onDidOptionChange: Event<void> = this._onDidOptionChange.event;
private _onKeyDown = this._register(new Emitter<StandardKeyboardEvent>());
public onKeyDown: Event<StandardKeyboardEvent> = this._onKeyDown.event;
constructor(parent:HTMLElement, contextViewProvider: ContextView.IContextViewProvider, options?:IOptions) {
private _onKeyUp = this._register(new Emitter<StandardKeyboardEvent>());
public onKeyUp: Event<StandardKeyboardEvent> = this._onKeyUp.event;
private _onCaseSensitiveKeyDown = this._register(new Emitter<StandardKeyboardEvent>());
public onCaseSensitiveKeyDown: Event<StandardKeyboardEvent> = this._onCaseSensitiveKeyDown.event;
constructor(parent:HTMLElement, contextViewProvider: IContextViewProvider, options?:IFindInputOptions) {
super();
this.contextViewProvider = contextViewProvider;
this.onOptionChange = null;
this.width = options.width || 100;
this.placeholder = options.placeholder || '';
this.validation = options.validation;
this.label = options.label || NLS_DEFAULT_LABEL;
this.listenersToRemove = [];
this.regex = null;
this.wholeWords = null;
this.caseSensitive = null;
this.domNode = null;
this.inputBox = null;
this.validationNode = null;
this.buildDomNode(options.appendCaseSensitiveLabel || '', options.appendWholeWordsLabel || '', options.appendRegexLabel || '');
if(Boolean(parent)) {
parent.appendChild(this.domNode);
}
}
public destroy(): void {
this.regex.destroy();
this.wholeWords.destroy();
this.caseSensitive.destroy();
this.listenersToRemove.forEach((element) => {
element();
});
this.listenersToRemove = [];
}
public on(eventType:string, handler:(event:Event)=>void): FindInput {
switch(eventType) {
case 'keydown':
case 'keyup':
$(this.inputBox.inputElement).on(eventType, handler);
break;
case FindInput.OPTION_CHANGE:
this.onOptionChange = handler;
break;
}
return this;
this.onkeydown(this.inputBox.inputElement, (e) => this._onKeyDown.fire(e));
this.onkeyup(this.inputBox.inputElement, (e) => this._onKeyUp.fire(e));
}
public enable(): void {
$(this.domNode).removeClass('disabled');
dom.removeClass(this.domNode, 'disabled');
this.inputBox.enable();
this.regex.enable();
this.wholeWords.enable();
......@@ -105,7 +100,7 @@ export class FindInput {
}
public disable(): void {
$(this.domNode).addClass('disabled');
dom.addClass(this.domNode, 'disabled');
this.inputBox.disable();
this.regex.disable();
this.wholeWords.disable();
......@@ -135,6 +130,11 @@ export class FindInput {
}
}
public setMatchCountState(state:IMatchCountState): void {
this.matchCount.setState(state);
this.setInputWidth();
}
public select(): void {
this.inputBox.select();
}
......@@ -144,29 +144,29 @@ export class FindInput {
}
public getCaseSensitive():boolean {
return this.caseSensitive.isChecked;
return this.caseSensitive.checked;
}
public setCaseSensitive(value:boolean): void {
this.caseSensitive.setChecked(value);
this.caseSensitive.checked = value;
this.setInputWidth();
}
public getWholeWords():boolean {
return this.wholeWords.isChecked;
return this.wholeWords.checked;
}
public setWholeWords(value:boolean): void {
this.wholeWords.setChecked(value);
this.wholeWords.checked = value;
this.setInputWidth();
}
public getRegex():boolean {
return this.regex.isChecked;
return this.regex.checked;
}
public setRegex(value:boolean): void {
this.regex.setChecked(value);
this.regex.checked = value;
this.setInputWidth();
}
......@@ -175,46 +175,72 @@ export class FindInput {
}
private setInputWidth(): void {
var w = this.width - this.caseSensitive.width() - this.wholeWords.width() - this.regex.width();
let w = this.width - this.matchCount.width() - this.caseSensitive.width() - this.wholeWords.width() - this.regex.width();
this.inputBox.width = w;
}
private buildDomNode(appendCaseSensitiveLabel:string, appendWholeWordsLabel: string, appendRegexLabel: string): void {
this.domNode = document.createElement('div');
this.domNode.style.width = this.width + 'px';
$(this.domNode).addClass('monaco-findInput');
dom.addClass(this.domNode, 'monaco-findInput');
this.inputBox = new InputBox.InputBox(this.domNode, this.contextViewProvider, {
this.inputBox = this._register(new InputBox(this.domNode, this.contextViewProvider, {
placeholder: this.placeholder || '',
ariaLabel: this.label || '',
validationOptions: {
validation: this.validation || null,
showMessage: true
}
});
}));
this.regex = this._register(new Checkbox({
actionClassName: 'regex',
title: NLS_REGEX_CHECKBOX_LABEL + appendRegexLabel,
isChecked: false,
onChange: () => {
this._onDidOptionChange.fire();
this.inputBox.focus();
this.setInputWidth();
this.validate();
}
}));
this.wholeWords = this._register(new Checkbox({
actionClassName: 'whole-word',
title: NLS_WHOLE_WORD_CHECKBOX_LABEL + appendWholeWordsLabel,
isChecked: false,
onChange: () => {
this._onDidOptionChange.fire();
this.inputBox.focus();
this.setInputWidth();
this.validate();
}
}));
this.caseSensitive = this._register(new Checkbox({
actionClassName: 'case-sensitive',
title: NLS_CASE_SENSITIVE_CHECKBOX_LABEL + appendCaseSensitiveLabel,
isChecked: false,
onChange: () => {
this._onDidOptionChange.fire();
this.inputBox.focus();
this.setInputWidth();
this.validate();
},
onKeyDown: (e) => {
this._onCaseSensitiveKeyDown.fire(e);
}
}));
this.matchCount = this._register(new MatchCount({
onClick: (e) => {
this.inputBox.focus();
e.preventDefault();
}
}));
this.regex = new Checkbox.Checkbox('regex', NLS_REGEX_CHECKBOX_LABEL + appendRegexLabel, false, () => {
this.onOptionChange(null);
this.inputBox.focus();
this.setInputWidth();
this.validate();
});
this.wholeWords = new Checkbox.Checkbox('whole-word', NLS_WHOLE_WORD_CHECKBOX_LABEL + appendWholeWordsLabel, false, () => {
this.onOptionChange(null);
this.inputBox.focus();
this.setInputWidth();
this.validate();
});
this.caseSensitive = new Checkbox.Checkbox('case-sensitive', NLS_CASE_SENSITIVE_CHECKBOX_LABEL + appendCaseSensitiveLabel, false, () => {
this.onOptionChange(null);
this.inputBox.focus();
this.setInputWidth();
this.validate();
});
this.setInputWidth();
var controls = document.createElement('div');
let controls = document.createElement('div');
controls.className = 'controls';
controls.appendChild(this.matchCount.domNode);
controls.appendChild(this.caseSensitive.domNode);
controls.appendChild(this.wholeWords.domNode);
controls.appendChild(this.regex.domNode);
......@@ -226,7 +252,7 @@ export class FindInput {
this.inputBox.validate();
}
public showMessage(message: InputBox.IMessage): void {
public showMessage(message: InputBoxMessage): void {
this.inputBox.showMessage(message);
}
......@@ -238,3 +264,43 @@ export class FindInput {
this.inputBox.hideMessage();
}
}
interface IMatchCountOpts {
onClick: (e:StandardMouseEvent) => void;
}
class MatchCount extends Widget {
public domNode: HTMLElement;
private isVisible: boolean;
constructor(opts:IMatchCountOpts) {
super();
this.domNode = document.createElement('div');
this.domNode.className = 'matchCount';
this.setState({
isVisible: false,
count: '0',
title: ''
});
this.onclick(this.domNode, opts.onClick);
}
public width(): number {
return this.isVisible ? 30 : 0;
}
public setState(state:IMatchCountState): void {
dom.clearNode(this.domNode);
this.domNode.appendChild(document.createTextNode(state.count));
this.domNode.title = state.title;
this.isVisible = state.isVisible;
if (this.isVisible) {
this.domNode.style.display = 'block';
} else {
this.domNode.style.display = 'none';
}
}
}
......@@ -5,18 +5,19 @@
'use strict';
import 'vs/css!./inputBox';
import Bal = require('vs/base/browser/browser');
import dom = require('vs/base/browser/dom');
import browser = require('vs/base/browser/browserService');
import htmlcontent = require('vs/base/common/htmlContent');
import renderer = require('vs/base/browser/htmlContentRenderer');
import ee = require('vs/base/common/eventEmitter');
import actions = require('vs/base/common/actions');
import actionBar = require('vs/base/browser/ui/actionbar/actionbar');
import lifecycle = require('vs/base/common/lifecycle');
import contextview = require('vs/base/browser/ui/contextview/contextview');
var $ = dom.emmet;
import * as Bal from 'vs/base/browser/browser';
import * as dom from 'vs/base/browser/dom';
import * as browser from 'vs/base/browser/browserService';
import {IHTMLContentElement} from 'vs/base/common/htmlContent';
import {renderHtml} from 'vs/base/browser/htmlContentRenderer';
import {IAction} from 'vs/base/common/actions';
import {ActionBar} from 'vs/base/browser/ui/actionbar/actionbar';
import {IContextViewProvider, AnchorAlignment} from 'vs/base/browser/ui/contextview/contextview';
import Event, {Emitter} from 'vs/base/common/event';
import {Widget} from 'vs/base/browser/ui/widget';
let $ = dom.emmet;
export interface IInputOptions {
placeholder?:string;
......@@ -24,7 +25,7 @@ export interface IInputOptions {
type?:string;
validationOptions?:IInputValidationOptions;
flexibleHeight?: boolean;
actions?:actions.IAction[];
actions?:IAction[];
}
export interface IInputValidator {
......@@ -53,14 +54,14 @@ export interface IRange {
end: number;
}
export class InputBox extends ee.EventEmitter {
export class InputBox extends Widget {
private contextViewProvider: contextview.IContextViewProvider;
private contextViewProvider: IContextViewProvider;
private element: HTMLElement;
private input: HTMLInputElement;
private mirror: HTMLElement;
private actionbar: actionBar.ActionBar;
private actionbar: ActionBar;
private options: IInputOptions;
private message: IMessage;
private placeholder: string;
......@@ -69,14 +70,19 @@ export class InputBox extends ee.EventEmitter {
private showValidationMessage: boolean;
private state = 'idle';
private cachedHeight: number;
private toDispose: lifecycle.IDisposable[];
constructor(container:HTMLElement, contextViewProvider: contextview.IContextViewProvider, options?: IInputOptions) {
private _onDidChange = this._register(new Emitter<string>());
public onDidChange: Event<string> = this._onDidChange.event;
private _onDidHeightChange = this._register(new Emitter<number>());
public onDidHeightChange: Event<number> = this._onDidHeightChange.event;
constructor(container:HTMLElement, contextViewProvider: IContextViewProvider, options?: IInputOptions) {
super();
this.contextViewProvider = contextViewProvider;
this.options = options || Object.create(null);
this.toDispose = [];
// this.toDispose = [];
this.message = null;
this.cachedHeight = null;
this.placeholder = this.options.placeholder || '';
......@@ -89,9 +95,9 @@ export class InputBox extends ee.EventEmitter {
this.element = dom.append(container, $('.monaco-inputbox.idle'));
var tagName = this.options.flexibleHeight ? 'textarea' : 'input';
let tagName = this.options.flexibleHeight ? 'textarea' : 'input';
var wrapper = dom.append(this.element, $('.wrapper'));
let wrapper = dom.append(this.element, $('.wrapper'));
this.input = <HTMLInputElement> dom.append(wrapper, $(tagName + '.input'));
this.input.setAttribute('autocorrect', 'off');
this.input.setAttribute('autocapitalize', 'off');
......@@ -112,22 +118,20 @@ export class InputBox extends ee.EventEmitter {
this.input.setAttribute('placeholder', this.placeholder);
}
this.toDispose.push(
dom.addDisposableListener(this.input, dom.EventType.INPUT, () => this.onValueChange()),
dom.addDisposableListener(this.input, dom.EventType.BLUR, () => this.onBlur()),
dom.addDisposableListener(this.input, dom.EventType.FOCUS, () => this.onFocus())
);
this.oninput(this.input, () => this.onValueChange());
this.onblur(this.input, () => this.onBlur());
this.onfocus(this.input, () => this.onFocus());
// Add placeholder shim for IE because IE decides to hide the placeholder on focus (we dont want that!)
if (this.placeholder && Bal.isIE11orEarlier) {
this.toDispose.push(dom.addDisposableListener(this.input, dom.EventType.CLICK, (e) => {
this.onclick(this.input, (e) => {
dom.EventHelper.stop(e, true);
this.input.focus();
}));
});
if (Bal.isIE9) {
this.toDispose.push(dom.addDisposableListener(this.input, 'keyup', () => this.onValueChange()));
this.onkeyup(this.input, () => this.onValueChange());
}
}
......@@ -135,7 +139,7 @@ export class InputBox extends ee.EventEmitter {
// Support actions
if (this.options.actions) {
this.actionbar = new actionBar.ActionBar(this.element);
this.actionbar = this._register(new ActionBar(this.element));
this.actionbar.push(this.options.actions, { icon: true, label: false });
}
}
......@@ -154,7 +158,7 @@ export class InputBox extends ee.EventEmitter {
}
}
public setContextViewProvider(contextViewProvider: contextview.IContextViewProvider): void {
public setContextViewProvider(contextViewProvider: IContextViewProvider): void {
this.contextViewProvider = contextViewProvider;
}
......@@ -244,7 +248,7 @@ export class InputBox extends ee.EventEmitter {
}
public validate(): boolean {
var result: IMessage = null;
let result: IMessage = null;
if (this.validation) {
result = this.validation(this.value);
......@@ -273,19 +277,19 @@ export class InputBox extends ee.EventEmitter {
return;
}
var div: HTMLElement;
var layout = () => div.style.width = dom.getTotalWidth(this.element) + 'px';
let div: HTMLElement;
let layout = () => div.style.width = dom.getTotalWidth(this.element) + 'px';
this.state = 'open';
this.contextViewProvider.showContextView({
getAnchor: () => this.element,
anchorAlignment: contextview.AnchorAlignment.RIGHT,
anchorAlignment: AnchorAlignment.RIGHT,
render: (container: HTMLElement) => {
div = dom.append(container, $('.monaco-inputbox-container'));
layout();
var renderOptions: htmlcontent.IHTMLContentElement = {
let renderOptions: IHTMLContentElement = {
tagName: 'span',
className: 'monaco-inputbox-message',
};
......@@ -296,7 +300,7 @@ export class InputBox extends ee.EventEmitter {
renderOptions.text = this.message.content;
}
var spanElement:HTMLElement = <any>renderer.renderHtml(renderOptions);
let spanElement:HTMLElement = <any>renderHtml(renderOptions);
dom.addClass(spanElement, this.classForType(this.message.type));
dom.append(div, spanElement);
return null;
......@@ -316,13 +320,13 @@ export class InputBox extends ee.EventEmitter {
}
private onValueChange(): void {
this.emit('change', this.value);
this._onDidChange.fire(this.value);
this.validate();
if (this.mirror) {
var lastCharCode = this.value.charCodeAt(this.value.length - 1);
var suffix = lastCharCode === 10 ? ' ' : '';
let lastCharCode = this.value.charCodeAt(this.value.length - 1);
let suffix = lastCharCode === 10 ? ' ' : '';
this.mirror.textContent = this.value + suffix;
this.layout();
}
......@@ -338,14 +342,11 @@ export class InputBox extends ee.EventEmitter {
if (previousHeight !== this.cachedHeight) {
this.input.style.height = this.cachedHeight + 'px';
this.emit('heightchange', this.cachedHeight);
this._onDidHeightChange.fire(this.cachedHeight);
}
}
public dispose(): void {
this.toDispose = lifecycle.disposeAll(this.toDispose);
this._hideMessage();
this.element = null;
......@@ -357,11 +358,7 @@ export class InputBox extends ee.EventEmitter {
this.validation = null;
this.showValidationMessage = null;
this.state = null;
if (this.actionbar) {
this.actionbar.dispose();
this.actionbar = null;
}
this.actionbar = null;
super.dispose();
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import {Disposable} from 'vs/base/common/lifecycle';
import {StandardMouseEvent} from 'vs/base/browser/mouseEvent';
import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import * as DomUtils from 'vs/base/browser/dom';
export abstract class Widget extends Disposable {
protected onclick(domNode:HTMLElement, listener:(e:StandardMouseEvent)=>void): void {
this._register(DomUtils.addDisposableListener(domNode, DomUtils.EventType.CLICK, (e:MouseEvent) => listener(new StandardMouseEvent(e))));
}
protected onkeydown(domNode:HTMLElement, listener:(e:StandardKeyboardEvent)=>void): void {
this._register(DomUtils.addDisposableListener(domNode, DomUtils.EventType.KEY_DOWN, (e:KeyboardEvent) => listener(new StandardKeyboardEvent(e))));
}
protected onkeyup(domNode:HTMLElement, listener:(e:StandardKeyboardEvent)=>void): void {
this._register(DomUtils.addDisposableListener(domNode, DomUtils.EventType.KEY_UP, (e:KeyboardEvent) => listener(new StandardKeyboardEvent(e))));
}
protected oninput(domNode:HTMLElement, listener:(e:Event)=>void): void {
this._register(DomUtils.addDisposableListener(domNode, DomUtils.EventType.INPUT, listener));
}
protected onblur(domNode:HTMLElement, listener:(e:Event)=>void): void {
this._register(DomUtils.addDisposableListener(domNode, DomUtils.EventType.BLUR, listener));
}
protected onfocus(domNode:HTMLElement, listener:(e:Event)=>void): void {
this._register(DomUtils.addDisposableListener(domNode, DomUtils.EventType.FOCUS, listener));
}
protected onchange(domNode:HTMLElement, listener:(e:Event)=>void): void {
this._register(DomUtils.addDisposableListener(domNode, DomUtils.EventType.CHANGE, listener));
}
}
......@@ -484,6 +484,7 @@ export class CommonKeybindings {
public static WINCTRL_ENTER: number = KeyMod.WinCtrl | KeyCode.Enter;
public static TAB: number = KeyCode.Tab;
public static SHIFT_TAB: number = KeyMod.Shift | KeyCode.Tab;
public static ESCAPE: number = KeyCode.Escape;
public static SPACE: number = KeyCode.Space;
public static DELETE: number = KeyCode.Delete;
......
......@@ -69,3 +69,21 @@ export interface CallAll {
* Calls all functions that are being passed to it.
*/
export const cAll: CallAll = callAll;
export abstract class Disposable implements IDisposable {
private _toDispose: IDisposable[];
constructor() {
this._toDispose = [];
}
public dispose(): void {
this._toDispose = disposeAll(this._toDispose);
}
protected _register<T extends IDisposable>(t:T): T {
this._toDispose.push(t);
return t;
}
}
......@@ -190,6 +190,7 @@ export abstract class AbstractProcess<TProgressData> {
} else {
let childProcess: ChildProcess = null;
let closeHandler = (data: any) => {
console.log("Close received");
this.childProcess = null;
this.childProcessPromise = null;
this.handleClose(data, cc, pp, ee);
......@@ -201,18 +202,6 @@ export abstract class AbstractProcess<TProgressData> {
}
cc(result);
}
let exitHandler = (data: any) => {
this.childProcess = null;
this.childProcessPromise = null;
this.handleExit(data, cc, pp, ee);
let result: SuccessData = {
terminated: this.terminateRequested
};
if (this.shell && Platform.isWindows && Types.isNumber(data)) {
result.cmdCode = <number>data;
}
cc(result);
};
if (this.shell && Platform.isWindows) {
let options: any = Objects.clone(this.options);
options.windowsVerbatimArguments = true;
......@@ -259,7 +248,6 @@ export abstract class AbstractProcess<TProgressData> {
}
this.childProcess = childProcess;
this.childProcess.on('close', closeHandler);
this.childProcess.on('exit', exitHandler);
this.handleSpawn(childProcess, cc, pp, ee, false);
c(childProcess);
});
......@@ -275,7 +263,6 @@ export abstract class AbstractProcess<TProgressData> {
});
if (childProcess.pid) {
this.childProcess.on('close', closeHandler);
this.childProcess.on('exit', exitHandler);
this.handleSpawn(childProcess, cc, pp, ee, true);
}
}
......@@ -290,9 +277,6 @@ export abstract class AbstractProcess<TProgressData> {
protected handleClose(data: any, cc: TValueCallback<SuccessData>, pp: TProgressCallback<TProgressData>, ee: ErrorCallback): void {
// Default is to do nothing.
}
protected handleExit(data: any, cc: TValueCallback<SuccessData>, pp: TProgressCallback<TProgressData>, ee: ErrorCallback): void {
// Default is to do nothing.
}
private static regexp = /^[^"].* .*[^"]/;
private ensureQuotes(value: string) {
......@@ -396,16 +380,6 @@ export class LineProcess extends AbstractProcess<LineData> {
}
});
}
protected handleExit(data: any, cc: TValueCallback<SuccessData>, pp: TProgressCallback<LineData>, ee: ErrorCallback): void {
if (this.terminateRequested) {
[this.stdoutLineDecoder.end(), this.stderrLineDecoder.end()].forEach((line, index) => {
if (line) {
pp({ line: line, source: index === 0 ? Source.stdout : Source.stderr });
}
});
}
}
}
export class BufferProcess extends AbstractProcess<BufferData> {
......
......@@ -6,28 +6,10 @@
'use strict';
import { Url, parse as parseUrl } from 'url';
import { isBoolean } from 'vs/base/common/types';
import HttpProxyAgent = require('http-proxy-agent');
import HttpsProxyAgent = require('https-proxy-agent');
function getAgent(rawRequestURL: string, proxyURL: string, strictSSL: boolean = true): any {
let requestURL = parseUrl(rawRequestURL);
let proxyEndpoint = parseUrl(proxyURL);
if (!/^https?:$/.test(proxyEndpoint.protocol)) {
return null;
}
if (requestURL.protocol === 'http:') {
return new HttpProxyAgent(proxyURL);
}
return new HttpsProxyAgent({
host: proxyEndpoint.hostname,
port: Number(proxyEndpoint.port),
rejectUnauthorized: strictSSL
});
}
function getSystemProxyURI(requestURL: Url): string {
if (requestURL.protocol === 'http:') {
return process.env.HTTP_PROXY || process.env.http_proxy || null;
......@@ -38,26 +20,32 @@ function getSystemProxyURI(requestURL: Url): string {
return null;
}
function getSystemProxyAgent(rawRequestURL: string): any {
let requestURL = parseUrl(rawRequestURL);
let proxyURL = getSystemProxyURI(requestURL);
export interface IOptions {
proxyUrl?: string;
strictSSL?: boolean;
}
export function getProxyAgent(rawRequestURL: string, options: IOptions = {}): any {
const requestURL = parseUrl(rawRequestURL);
const proxyURL = options.proxyUrl || getSystemProxyURI(requestURL);
if (!proxyURL) {
return null;
}
return getAgent(rawRequestURL, proxyURL);
}
const proxyEndpoint = parseUrl(proxyURL);
export interface IOptions {
proxyUrl?: string;
strictSSL?: boolean;
}
if (!/^https?:$/.test(proxyEndpoint.protocol)) {
return null;
}
export function getProxyAgent(rawRequestURL: string, options: IOptions = {}): any {
if (!options.proxyUrl) {
return getSystemProxyAgent(rawRequestURL);
if (requestURL.protocol === 'http:') {
return new HttpProxyAgent(proxyURL);
}
return getAgent(rawRequestURL, options.proxyUrl, options.strictSSL);
return new HttpsProxyAgent({
host: proxyEndpoint.hostname,
port: Number(proxyEndpoint.port),
rejectUnauthorized: isBoolean(options.strictSSL) ? options.strictSSL : true
});
}
\ No newline at end of file
......@@ -48,7 +48,7 @@ function generatePatchedEnv(env:any, stdInPipeName:string, stdOutPipeName:string
newEnv['STDIN_PIPE_NAME'] = stdInPipeName;
newEnv['STDOUT_PIPE_NAME'] = stdOutPipeName;
newEnv['ELECTRON_RUN_AS_NODE'] = '1';
newEnv['ATOM_SHELL_INTERNAL_RUN_AS_NODE'] = '1';
return newEnv;
}
......
......@@ -31,7 +31,7 @@ var stdOutPipeName = process.env['STDOUT_PIPE_NAME'];
log('STDIN_PIPE_NAME: ' + stdInPipeName);
log('STDOUT_PIPE_NAME: ' + stdOutPipeName);
log('ELECTRON_RUN_AS_NODE: ' + process.env['ELECTRON_RUN_AS_NODE']);
log('ATOM_SHELL_INTERNAL_RUN_AS_NODE: ' + process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE']);
// stdout redirection to named pipe
(function() {
......@@ -136,7 +136,7 @@ log('ELECTRON_RUN_AS_NODE: ' + process.env['ELECTRON_RUN_AS_NODE']);
// Unset the custom environmental variables that should not get inherited
delete process.env['STDIN_PIPE_NAME'];
delete process.env['STDOUT_PIPE_NAME'];
delete process.env['ELECTRON_RUN_AS_NODE'];
delete process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
require(program);
......
......@@ -573,6 +573,41 @@ export interface ICodeEditor extends EditorCommon.ICommonCodeEditor {
* Change the view zones. View zones are lost when a new model is attached to the editor.
*/
changeViewZones(callback: (accessor: IViewZoneChangeAccessor) => void): void;
/**
* Returns the range that is currently centered in the view port.
*/
getCenteredRangeInViewport(): EditorCommon.IEditorRange;
/**
* Get the view zones.
*/
getWhitespaces(): EditorCommon.IEditorWhitespace[];
/**
* Get the horizontal position (left offset) for the column w.r.t to the beginning of the line.
* This method works only if the line `lineNumber` is currently rendered (in the editor's viewport).
* Use this method with caution.
*/
getOffsetForColumn(lineNumber: number, column: number): number;
/**
* Get the vertical position (top offset) for the line w.r.t. to the first line.
*/
getTopForLineNumber(lineNumber: number): number;
/**
* Get the vertical position (top offset) for the position w.r.t. to the first line.
*/
getTopForPosition(lineNumber: number, column: number): number;
/**
* Get the visible position for `position`.
* The result position takes scrolling into account and is relative to the top left corner of the editor.
* Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor.
* Explanation 2: the results of this method will not change if the container of the editor gets repositioned.
* Warning: the results of this method are innacurate for positions that are outside the current editor viewport.
*/
getScrolledVisiblePosition(position: EditorCommon.IPosition): { top: number; left: number; height: number; };
}
/**
......
此差异已折叠。
......@@ -1758,6 +1758,16 @@ export interface IModel extends IEditableTextModel, ITextModelWithMarkers, IToke
* @return The range where the next match is. It is null if no next match has been found.
*/
findNextMatch(searchString:string, searchStart:IPosition, isRegex:boolean, matchCase:boolean, wholeWord:boolean): IEditorRange;
/**
* Search the model for the previous match. Loops to the end of the model if needed.
* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
* @param searchStart Start the searching at the specified position.
* @param isRegex Used to indicate that `searchString` is a regular expression.
* @param matchCase Force the matching to match lower/upper case exactly.
* @param wholeWord Force the matching to match entire words only.
* @return The range where the previous match is. It is null if no previous match has been found.
*/
findPreviousMatch(searchString:string, searchStart:IPosition, isRegex:boolean, matchCase:boolean, wholeWord:boolean): IEditorRange;
/**
* Replace the entire text buffer value contained in this model.
......@@ -3037,11 +3047,6 @@ export interface ICommonCodeEditor extends IEditor {
*/
setValue(newValue: string): void;
/**
* Returns the range that is currently centered in the view port.
*/
getCenteredRangeInViewport(): IEditorRange;
/**
* Change the scrollTop of the editor's viewport.
*/
......@@ -3113,42 +3118,11 @@ export interface ICommonCodeEditor extends IEditor {
removeDecorations(decorationTypeKey:string): void;
/**
* Get the horizontal position (left offset) for the column w.r.t to the beginning of the line.
* This method works only if the line `lineNumber` is currently rendered (in the editor's viewport).
* Use this method with caution.
*/
getOffsetForColumn(lineNumber: number, column: number): number;
/**
* Get the vertical position (top offset) for the line w.r.t. to the first line.
*/
getTopForLineNumber(lineNumber: number): number;
/**
* Get the vertical position (top offset) for the position w.r.t. to the first line.
*/
getTopForPosition(lineNumber: number, column: number): number;
/**
* Get the visible position for `position`.
* The result position takes scrolling into account and is relative to the top left corner of the editor.
* Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor.
* Explanation 2: the results of this method will not change if the container of the editor gets repositioned.
* Warning: the results of this method are innacurate for positions that are outside the current editor viewport.
*/
getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number; };
/**
* Get the layout info for the editor.
*/
getLayoutInfo(): IEditorLayoutInfo;
/**
* Get the view zones.
*/
getWhitespaces(): IEditorWhitespace[];
/**
* Prevent the editor from sending a widgetFocusLost event,
* set it in a state where it believes that focus is in one of its widgets.
......
......@@ -904,6 +904,41 @@ export class TextModel extends OrderGuaranteeEventEmitter implements EditorCommo
return null;
}
public findPreviousMatch(searchString:string, rawSearchStart:EditorCommon.IPosition, isRegex:boolean, matchCase:boolean, wholeWord:boolean): EditorCommon.IEditorRange {
if (this._isDisposed) {
throw new Error('Model.findPreviousMatch: Model is disposed');
}
var regex = Strings.createSafeRegExp(searchString, isRegex, matchCase, wholeWord);
if (!regex) {
return null;
}
var searchStart = this.validatePosition(rawSearchStart),
lineCount = this.getLineCount(),
startLineNumber = searchStart.lineNumber,
text: string,
r: EditorCommon.IEditorRange;
// Look in first line
text = this._lines[startLineNumber - 1].text.substring(0, searchStart.column - 1);
r = this._findLastMatchInLine(regex, text, startLineNumber);
if (r) {
return r;
}
for (var i = 1; i < lineCount; i++) {
var lineIndex = (lineCount + startLineNumber - i - 1) % lineCount;
text = this._lines[lineIndex].text;
r = this._findLastMatchInLine(regex, text, lineIndex + 1);
if (r) {
return r;
}
}
return null;
}
private _doFindMatches(searchRange:EditorCommon.IEditorRange, searchRegex:RegExp, limitResultCount:number): EditorCommon.IEditorRange[] {
var result:EditorCommon.IEditorRange[] = [],
text: string,
......@@ -942,6 +977,19 @@ export class TextModel extends OrderGuaranteeEventEmitter implements EditorCommo
return new Range(lineNumber, m.index + 1 + deltaOffset, lineNumber, m.index + 1 + m[0].length + deltaOffset);
}
private _findLastMatchInLine(searchRegex:RegExp, text:string, lineNumber:number): EditorCommon.IEditorRange {
let bestResult: EditorCommon.IEditorRange = null;
let m:RegExpExecArray;
while ((m = searchRegex.exec(text))) {
let result = new Range(lineNumber, m.index + 1, lineNumber, m.index + 1 + m[0].length);
if (result.equalsRange(bestResult)) {
break;
}
bestResult = result;
}
return bestResult;
}
private _findMatchesInLine(searchRegex:RegExp, text:string, lineNumber:number, deltaOffset:number, counter:number, result:EditorCommon.IEditorRange[], limitResultCount:number): number {
var m:RegExpExecArray;
// Reset regex to search from the beginning
......
......@@ -232,10 +232,16 @@ export class LineCommentCommand implements EditorCommon.ICommand {
}
private _attemptRemoveBlockComment(model:EditorCommon.ITokenizedModel, s:EditorCommon.IEditorSelection, startToken: string, endToken: string): EditorCommon.IIdentifiedSingleEditOperation[] {
var startLineNumber = s.startLineNumber;
var endLineNumber = s.endLineNumber;
var startTokenIndex = model.getLineContent(startLineNumber).lastIndexOf(startToken, s.startColumn - 1 + endToken.length);
var endTokenIndex = model.getLineContent(endLineNumber).indexOf(endToken, s.endColumn - 1 - startToken.length);
let startLineNumber = s.startLineNumber;
let endLineNumber = s.endLineNumber;
let startTokenAllowedBeforeColumn = endToken.length + Math.max(
model.getLineFirstNonWhitespaceColumn(s.startLineNumber),
s.startColumn
);
let startTokenIndex = model.getLineContent(startLineNumber).lastIndexOf(startToken, startTokenAllowedBeforeColumn - 1);
let endTokenIndex = model.getLineContent(endLineNumber).indexOf(endToken, s.endColumn - 1 - startToken.length);
if (startTokenIndex !== -1 && endTokenIndex === -1) {
endTokenIndex = model.getLineContent(startLineNumber).indexOf(endToken, startTokenIndex + startToken.length);
......
......@@ -759,6 +759,38 @@ suite('Editor Contrib - Line Comment As Block Comment 2', () => {
new Selection(5, 10, 5, 10)
);
});
test('issue #993: Remove comment does not work consistently in HTML', () => {
testLineCommentCommand(
[
' asd qwe',
' asd qwe',
''
],
new Selection(1, 1, 3, 1),
[
' <!@#asd qwe',
' asd qwe#@!>',
''
],
new Selection(1, 1, 3, 1)
);
testLineCommentCommand(
[
' <!@#asd qwe',
' asd qwe#@!>',
''
],
new Selection(1, 1, 3, 1),
[
' asd qwe',
' asd qwe',
''
],
new Selection(1, 1, 3, 1)
);
});
});
......@@ -11,16 +11,15 @@ import * as nls from 'vs/nls';
import * as Errors from 'vs/base/common/errors';
import * as DomUtils from 'vs/base/browser/dom';
import {IContextViewProvider} from 'vs/base/browser/ui/contextview/contextview';
import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {InputBox, IMessage as InputBoxMessage} from 'vs/base/browser/ui/inputbox/inputBox';
import {FindInput} from 'vs/base/browser/ui/findinput/findInput';
import * as EditorBrowser from 'vs/editor/browser/editorBrowser';
import * as EditorCommon from 'vs/editor/common/editorCommon';
import {FIND_IDS} from 'vs/editor/contrib/find/common/findModel';
import {disposeAll, IDisposable} from 'vs/base/common/lifecycle';
import {MATCHES_LIMIT, FIND_IDS} from 'vs/editor/contrib/find/common/findModel';
import {CommonKeybindings} from 'vs/base/common/keyCodes';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {INewFindReplaceState, FindReplaceStateChangedEvent, FindReplaceState} from 'vs/editor/contrib/find/common/findState';
import {Widget} from 'vs/base/browser/ui/widget';
export interface IFindController {
replace(): void;
......@@ -38,8 +37,9 @@ const NLS_REPLACE_INPUT_PLACEHOLDER = nls.localize('placeholder.replace', "Repla
const NLS_REPLACE_BTN_LABEL = nls.localize('label.replaceButton', "Replace");
const NLS_REPLACE_ALL_BTN_LABEL = nls.localize('label.replaceAllButton', "Replace All");
const NLS_TOGGLE_REPLACE_MODE_BTN_LABEL = nls.localize('label.toggleReplaceButton', "Toggle Replace mode");
const NLS_MATCHES_COUNT_LIMIT_TITLE = nls.localize('title.matchesCountLimit', "Only the first 999 results are highlighted, but all find operations work on the entire text.");
export class FindWidget implements EditorBrowser.IOverlayWidget {
export class FindWidget extends Widget implements EditorBrowser.IOverlayWidget {
private static ID = 'editor.contrib.findWidget';
private static PART_WIDTH = 275;
......@@ -59,7 +59,7 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
private _toggleReplaceBtn: SimpleButton;
private _prevBtn: SimpleButton;
private _nextBtn: SimpleButton;
private _toggleSelectionFind: Checkbox;
private _toggleSelectionFind: SimpleCheckbox;
private _closeBtn: SimpleButton;
private _replaceBtn: SimpleButton;
private _replaceAllBtn: SimpleButton;
......@@ -68,8 +68,6 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
private _isVisible: boolean;
private _isReplaceVisible: boolean;
private _toDispose: IDisposable[];
private focusTracker: DomUtils.IFocusTracker;
constructor(
......@@ -79,6 +77,7 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
contextViewProvider: IContextViewProvider,
keybindingService: IKeybindingService
) {
super();
this._codeEditor = codeEditor;
this._controller = controller;
this._state = state;
......@@ -88,30 +87,31 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
this._isVisible = false;
this._isReplaceVisible = false;
this._isReplaceEnabled = false;
this._toDispose = [];
this._toDispose.push(this._state.addChangeListener((e) => this._onStateChanged(e)));
this._register(this._state.addChangeListener((e) => this._onStateChanged(e)));
this._buildDomNode();
this.focusTracker = DomUtils.trackFocus(this._findInput.inputBox.inputElement);
this.focusTracker = this._register(DomUtils.trackFocus(this._findInput.inputBox.inputElement));
this.focusTracker.addFocusListener(() => this._reseedFindScope());
this._toDispose.push(this.focusTracker);
this._toDispose.push({
dispose: () => {
this._findInput.destroy();
let updateCanReplace = () => {
let canReplace = !this._codeEditor.getConfiguration().readOnly;
DomUtils.toggleClass(this._domNode, 'can-replace', canReplace);
if (!canReplace) {
this._state.change({ isReplaceRevealed: false }, false);
}
});
this._toDispose.push(this._replaceInputBox);
};
this._register(this._codeEditor.addListener2(EditorCommon.EventType.ConfigurationChanged, (e:EditorCommon.IConfigurationChangedEvent) => {
if (e.readOnly) {
updateCanReplace();
}
}));
updateCanReplace();
this._codeEditor.addOverlayWidget(this);
}
public dispose(): void {
this._toDispose = disposeAll(this._toDispose);
}
private _reseedFindScope(): void {
let selection = this._codeEditor.getSelection();
if (selection.startLineNumber !== selection.endLineNumber) {
......@@ -179,15 +179,30 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
}
if (e.searchScope) {
if (this._state.searchScope) {
this._toggleSelectionFind.checkbox.checked = true;
this._toggleSelectionFind.checked = true;
} else {
this._toggleSelectionFind.checkbox.checked = false;
this._toggleSelectionFind.checked = false;
}
this._updateToggleSelectionFindButton();
}
if (e.searchString || e.matchesCount) {
let showRedOutline = (this._state.searchString.length > 0 && this._state.matchesCount === 0);
DomUtils.toggleClass(this._domNode, 'no-results', showRedOutline);
let showMatchesCount = (this._state.searchString.length > 0);
let matchesCount:string = String(this._state.matchesCount);
let matchesCountTitle = '';
if (this._state.matchesCount >= MATCHES_LIMIT) {
matchesCountTitle = NLS_MATCHES_COUNT_LIMIT_TITLE;
matchesCount += '+';
}
this._findInput.setMatchCountState({
isVisible: showMatchesCount,
count: matchesCount,
title: matchesCountTitle
});
}
}
......@@ -231,61 +246,70 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
private _onFindInputKeyDown(e:DomUtils.IKeyboardEvent): void {
let handled = false;
switch (e.asKeybinding()) {
case CommonKeybindings.ENTER:
this._codeEditor.getAction(FIND_IDS.NextMatchFindAction).run().done(null, Errors.onUnexpectedError);
e.preventDefault();
return;
if (e.equals(CommonKeybindings.ENTER)) {
this._codeEditor.getAction(FIND_IDS.NextMatchFindAction).run().done(null, Errors.onUnexpectedError);
handled = true;
} else if (e.equals(CommonKeybindings.SHIFT_ENTER)) {
this._codeEditor.getAction(FIND_IDS.PreviousMatchFindAction).run().done(null, Errors.onUnexpectedError);
handled = true;
} else if (e.equals(CommonKeybindings.TAB)) {
if (this._isReplaceVisible) {
this._replaceInputBox.focus();
} else {
this._findInput.focusOnCaseSensitive();
}
handled = true;
} else if (e.equals(CommonKeybindings.CTRLCMD_DOWN_ARROW)) {
this._codeEditor.focus();
handled = true;
}
case CommonKeybindings.SHIFT_ENTER:
this._codeEditor.getAction(FIND_IDS.PreviousMatchFindAction).run().done(null, Errors.onUnexpectedError);
e.preventDefault();
return;
if (handled) {
e.preventDefault();
} else {
// getValue() is not updated right away
setTimeout(() => {
this._state.change({ searchString: this._findInput.getValue() }, true);
}, 10);
case CommonKeybindings.TAB:
if (this._isReplaceVisible) {
this._replaceInputBox.focus();
} else {
this._findInput.focusOnCaseSensitive();
}
e.preventDefault();
return;
case CommonKeybindings.CTRLCMD_DOWN_ARROW:
this._codeEditor.focus();
e.preventDefault();
return;
}
// getValue() is not updated right away
setTimeout(() => {
this._state.change({ searchString: this._findInput.getValue() }, true);
}, 10);
}
private _onReplaceInputKeyDown(e:DomUtils.IKeyboardEvent): void {
let handled = false;
if (e.equals(CommonKeybindings.ENTER)) {
this._controller.replace();
handled = true;
} else if (e.equals(CommonKeybindings.CTRLCMD_ENTER)) {
this._controller.replaceAll();
handled = true;
} else if (e.equals(CommonKeybindings.TAB)) {
this._findInput.focusOnCaseSensitive();
handled = true;
} else if (e.equals(CommonKeybindings.CTRLCMD_DOWN_ARROW)) {
this._codeEditor.focus();
handled = true;
}
switch (e.asKeybinding()) {
case CommonKeybindings.ENTER:
this._controller.replace();
e.preventDefault();
return;
if (handled) {
e.preventDefault();
} else {
setTimeout(() => {
this._state.change({ replaceString: this._replaceInputBox.value }, false);
}, 10);
case CommonKeybindings.CTRLCMD_ENTER:
this._controller.replaceAll();
e.preventDefault();
return;
case CommonKeybindings.TAB:
this._findInput.focusOnCaseSensitive();
e.preventDefault();
return;
case CommonKeybindings.SHIFT_TAB:
this._findInput.focus();
e.preventDefault();
return;
case CommonKeybindings.CTRLCMD_DOWN_ARROW:
this._codeEditor.focus();
e.preventDefault();
return;
}
setTimeout(() => {
this._state.change({ replaceString: this._replaceInputBox.value }, false);
}, 10);
}
// ----- initialization
......@@ -300,7 +324,7 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
private _buildFindPart(): HTMLElement {
// Find input
this._findInput = new FindInput(null, this._contextViewProvider, {
this._findInput = this._register(new FindInput(null, this._contextViewProvider, {
width: FindWidget.FIND_INPUT_AREA_WIDTH,
label: NLS_FIND_INPUT_LABEL,
placeholder: NLS_FIND_INPUT_PLACEHOLDER,
......@@ -321,39 +345,45 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
return { content: e.message };
}
}
}).on('keydown', (browserEvent:KeyboardEvent) => {
this._onFindInputKeyDown(new StandardKeyboardEvent(browserEvent));
}).on(FindInput.OPTION_CHANGE, () => {
}));
this._register(this._findInput.onKeyDown((e) => this._onFindInputKeyDown(e)));
this._register(this._findInput.onDidOptionChange(() => {
this._state.change({
isRegex: this._findInput.getRegex(),
wholeWord: this._findInput.getWholeWords(),
matchCase: this._findInput.getCaseSensitive()
}, true);
});
}));
this._register(this._findInput.onCaseSensitiveKeyDown((e) => {
if (e.equals(CommonKeybindings.SHIFT_TAB)) {
if (this._isReplaceVisible) {
this._replaceInputBox.focus();
e.preventDefault();
}
}
}));
this._findInput.disable();
// Previous button
this._prevBtn = new SimpleButton({
this._prevBtn = this._register(new SimpleButton({
label: NLS_PREVIOUS_MATCH_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.PreviousMatchFindAction),
className: 'previous',
onTrigger: () => {
this._codeEditor.getAction(FIND_IDS.PreviousMatchFindAction).run().done(null, Errors.onUnexpectedError);
},
onKeyDown: (e) => {}
});
this._toDispose.push(this._prevBtn);
}));
// Next button
this._nextBtn = new SimpleButton({
this._nextBtn = this._register(new SimpleButton({
label: NLS_NEXT_MATCH_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.NextMatchFindAction),
className: 'next',
onTrigger: () => {
this._codeEditor.getAction(FIND_IDS.NextMatchFindAction).run().done(null, Errors.onUnexpectedError);
},
onKeyDown: (e) => {}
});
this._toDispose.push(this._nextBtn);
}));
let findPart = document.createElement('div');
findPart.className = 'find-part';
......@@ -362,35 +392,43 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
findPart.appendChild(this._nextBtn.domNode);
// Toggle selection button
this._toggleSelectionFind = new Checkbox(findPart, NLS_TOGGLE_SELECTION_FIND_TITLE);
this._toggleSelectionFind.disable();
this._toDispose.push(DomUtils.addStandardDisposableListener(this._toggleSelectionFind.checkbox, 'change', (e) => {
if (this._toggleSelectionFind.checkbox.checked) {
this._reseedFindScope();
} else {
this._state.change({ searchScope: null }, true);
this._toggleSelectionFind = this._register(new SimpleCheckbox({
parent: findPart,
title: NLS_TOGGLE_SELECTION_FIND_TITLE,
onChange: () => {
if (this._toggleSelectionFind.checked) {
this._reseedFindScope();
} else {
this._state.change({ searchScope: null }, true);
}
}
}));
this._toggleSelectionFind.disable();
this._codeEditor.addListener(EditorCommon.EventType.CursorSelectionChanged, () => {
this._updateToggleSelectionFindButton();
});
// Close button
this._closeBtn = new SimpleButton({
this._closeBtn = this._register(new SimpleButton({
label: NLS_CLOSE_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.CloseFindWidgetCommand),
className: 'close-fw',
onTrigger: () => {
this._state.change({ isRevealed: false }, false);
},
onKeyDown: (e) => {
if (this._isReplaceVisible) {
this._replaceBtn.focus();
e.preventDefault();
if (e.equals(CommonKeybindings.TAB)) {
if (this._isReplaceVisible) {
if (this._replaceBtn.isEnabled()) {
this._replaceBtn.focus();
} else {
this._codeEditor.focus();
}
e.preventDefault();
}
}
}
});
this._toDispose.push(this._closeBtn);
}));
findPart.appendChild(this._closeBtn.domNode);
......@@ -406,7 +444,7 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
return;
}
if (!this._toggleSelectionFind.checkbox.checked) {
if (!this._toggleSelectionFind.checked) {
let selection = this._codeEditor.getSelection();
if (selection.startLineNumber === selection.endLineNumber) {
......@@ -422,35 +460,38 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
let replaceInput = document.createElement('div');
replaceInput.className = 'replace-input';
replaceInput.style.width = FindWidget.REPLACE_INPUT_AREA_WIDTH + 'px';
this._replaceInputBox = new InputBox(replaceInput, null, {
this._replaceInputBox = this._register(new InputBox(replaceInput, null, {
ariaLabel: NLS_REPLACE_INPUT_LABEL,
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER
});
}));
this._toDispose.push(DomUtils.addStandardDisposableListener(this._replaceInputBox.inputElement, 'keydown', (e) => this._onReplaceInputKeyDown(e)));
this._register(DomUtils.addStandardDisposableListener(this._replaceInputBox.inputElement, 'keydown', (e) => this._onReplaceInputKeyDown(e)));
this._replaceInputBox.disable();
// Replace one button
this._replaceBtn = new SimpleButton({
this._replaceBtn = this._register(new SimpleButton({
label: NLS_REPLACE_BTN_LABEL,
className: 'replace',
onTrigger: () => {
this._controller.replace();
},
onKeyDown: (e) => {}
});
this._toDispose.push(this._replaceBtn);
onKeyDown: (e) => {
if (e.equals(CommonKeybindings.SHIFT_TAB)) {
this._closeBtn.focus();
e.preventDefault();
}
}
}));
// Replace all button
this._replaceAllBtn = new SimpleButton({
this._replaceAllBtn = this._register(new SimpleButton({
label: NLS_REPLACE_ALL_BTN_LABEL,
className: 'replace-all',
onTrigger: () => {
this._controller.replaceAll();
},
onKeyDown: (e) => {}
});
this._toDispose.push(this._replaceAllBtn);
}));
let replacePart = document.createElement('div');
replacePart.className = 'replace-part';
......@@ -469,28 +510,23 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
let replacePart = this._buildReplacePart();
// Toggle replace button
this._toggleReplaceBtn = new SimpleButton({
this._toggleReplaceBtn = this._register(new SimpleButton({
label: NLS_TOGGLE_REPLACE_MODE_BTN_LABEL,
className: 'toggle left',
onTrigger: () => {
this._state.change({ isReplaceRevealed: !this._isReplaceVisible }, true);
},
onKeyDown: (e) => {}
});
}));
this._toggleReplaceBtn.toggleClass('expand', this._isReplaceVisible);
this._toggleReplaceBtn.toggleClass('collapse', !this._isReplaceVisible);
this._toggleReplaceBtn.setExpanded(this._isReplaceVisible);
this._toDispose.push(this._toggleReplaceBtn);
// Widget
this._domNode = document.createElement('div');
this._domNode.className = 'editor-widget find-widget';
this._domNode.setAttribute('aria-hidden', 'false');
if (!this._codeEditor.getConfiguration().readOnly) {
DomUtils.addClass(this._domNode, 'can-replace');
}
this._domNode.appendChild(this._toggleReplaceBtn.domNode);
this._domNode.appendChild(findPart);
this._domNode.appendChild(replacePart);
......@@ -550,23 +586,33 @@ export class FindWidget implements EditorBrowser.IOverlayWidget {
}
}
export class Checkbox {
interface ISimpleCheckboxOpts {
parent: HTMLElement;
title: string;
onChange: () => void;
}
class SimpleCheckbox extends Widget {
private static _COUNTER = 0;
private _opts: ISimpleCheckboxOpts;
private _domNode: HTMLElement;
private _checkbox: HTMLInputElement;
private _label: HTMLLabelElement;
constructor(parent: HTMLElement, title: string) {
constructor(opts:ISimpleCheckboxOpts) {
super();
this._opts = opts;
this._domNode = document.createElement('div');
this._domNode.className = 'monaco-checkbox';
this._domNode.title = title;
this._domNode.title = this._opts.title;
this._checkbox = document.createElement('input');
this._checkbox.type = 'checkbox';
this._checkbox.className = 'checkbox';
this._checkbox.id = 'checkbox-' + Checkbox._COUNTER++;
this._checkbox.id = 'checkbox-' + SimpleCheckbox._COUNTER++;
this._label = document.createElement('label');
this._label.className = 'label';
......@@ -576,15 +622,23 @@ export class Checkbox {
this._domNode.appendChild(this._checkbox);
this._domNode.appendChild(this._label);
parent.appendChild(this._domNode);
this._opts.parent.appendChild(this._domNode);
this.onchange(this._checkbox, (e) => {
this._opts.onChange();
});
}
public get domNode(): HTMLElement {
return this._domNode;
}
public get checkbox(): HTMLInputElement {
return this._checkbox;
public get checked(): boolean {
return this._checkbox.checked;
}
public set checked(newValue:boolean) {
this._checkbox.checked = newValue;
}
public focus(): void {
......@@ -607,45 +661,44 @@ interface ISimpleButtonOpts {
onKeyDown: (e:DomUtils.IKeyboardEvent)=>void;
}
class SimpleButton implements IDisposable {
class SimpleButton extends Widget {
private _opts: ISimpleButtonOpts;
private _domNode: HTMLElement;
private _toDispose: IDisposable[];
constructor(opts:ISimpleButtonOpts) {
super();
this._opts = opts;
this._domNode = document.createElement('div');
this._domNode.title = this._opts.label;
this._domNode.tabIndex = -1;
this._domNode.tabIndex = 0;
this._domNode.className = 'button ' + this._opts.className;
this._domNode.setAttribute('role', 'button');
this._domNode.setAttribute('aria-label', this._opts.label);
this._toDispose = [];
this._toDispose.push(DomUtils.addStandardDisposableListener(this._domNode, 'click', (e) => {
this.onclick(this._domNode, (e) => {
this._opts.onTrigger();
e.preventDefault();
}));
this._toDispose.push(DomUtils.addStandardDisposableListener(this._domNode, 'keydown', (e) => {
});
this.onkeydown(this._domNode, (e) => {
if (e.equals(CommonKeybindings.SPACE) || e.equals(CommonKeybindings.ENTER)) {
this._opts.onTrigger();
e.preventDefault();
return;
}
this._opts.onKeyDown(e);
}));
}
public dispose(): void {
this._toDispose = disposeAll(this._toDispose);
});
}
public get domNode(): HTMLElement {
return this._domNode;
}
public isEnabled(): boolean {
return (this._domNode.tabIndex >= 0);
}
public focus(): void {
this._domNode.focus();
}
......
此差异已折叠。
......@@ -4,123 +4,80 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import EditorCommon = require('vs/editor/common/editorCommon');
import Strings = require('vs/base/common/strings');
import Events = require('vs/base/common/eventEmitter');
import ReplaceAllCommand = require('./replaceAllCommand');
import Lifecycle = require('vs/base/common/lifecycle');
import Schedulers = require('vs/base/common/async');
import {Range} from 'vs/editor/common/core/range';
import {Position} from 'vs/editor/common/core/position';
import {ReplaceCommand} from 'vs/editor/common/commands/replaceCommand';
export class FindDecorations implements Lifecycle.IDisposable {
private editor:EditorCommon.ICommonCodeEditor;
private decorations:string[];
private decorationIndex:number;
private findScopeDecorationId:string;
private highlightedDecorationId:string;
private startPosition:EditorCommon.IEditorPosition;
import * as EditorCommon from 'vs/editor/common/editorCommon';
import {IDisposable} from 'vs/base/common/lifecycle';
export class FindDecorations implements IDisposable {
private _editor:EditorCommon.ICommonCodeEditor;
private _decorations:string[];
private _findScopeDecorationId:string;
private _highlightedDecorationId:string;
private _startPosition:EditorCommon.IEditorPosition;
constructor(editor:EditorCommon.ICommonCodeEditor) {
this.editor = editor;
this.decorations = [];
this.decorationIndex = 0;
this.findScopeDecorationId = null;
this.highlightedDecorationId = null;
this.startPosition = this.editor.getPosition();
this._editor = editor;
this._decorations = [];
this._findScopeDecorationId = null;
this._highlightedDecorationId = null;
this._startPosition = this._editor.getPosition();
}
public dispose(): void {
this.editor.deltaDecorations(this._allDecorations(), []);
this.editor = null;
this.decorations = [];
this.decorationIndex = 0;
this.findScopeDecorationId = null;
this.highlightedDecorationId = null;
this.startPosition = null;
this._editor.deltaDecorations(this._allDecorations(), []);
this._editor = null;
this._decorations = [];
this._findScopeDecorationId = null;
this._highlightedDecorationId = null;
this._startPosition = null;
}
public reset(): void {
this.decorations = [];
this.decorationIndex = -1;
this.findScopeDecorationId = null;
this.highlightedDecorationId = null;
this._decorations = [];
this._findScopeDecorationId = null;
this._highlightedDecorationId = null;
}
public getFindScope(): EditorCommon.IEditorRange {
if (this.findScopeDecorationId) {
return this.editor.getModel().getDecorationRange(this.findScopeDecorationId);
if (this._findScopeDecorationId) {
return this._editor.getModel().getDecorationRange(this._findScopeDecorationId);
}
return null;
}
public setStartPosition(newStartPosition:EditorCommon.IEditorPosition): void {
this.startPosition = newStartPosition;
this._setDecorationIndex(-1, false);
}
public hasMatches(): boolean {
return (this.decorations.length > 0);
public getStartPosition(): EditorCommon.IEditorPosition {
return this._startPosition;
}
public setIndexToFirstAfterStartPosition(): void {
this._setDecorationIndex(this.indexAfterPosition(this.startPosition), false);
}
public moveToFirstAfterStartPosition(): void {
this._setDecorationIndex(this.indexAfterPosition(this.startPosition), true);
}
public movePrev(): void {
if (!this.hasMatches()) {
this._revealFindScope();
return;
}
if (this.decorationIndex === -1) {
this._setDecorationIndex(this.previousIndex(this.indexAfterPosition(this.startPosition)), true);
} else {
this._setDecorationIndex(this.previousIndex(this.decorationIndex), true);
}
}
public moveNext(): void {
if (!this.hasMatches()) {
this._revealFindScope();
return;
}
if (this.decorationIndex === -1) {
this._setDecorationIndex(this.indexAfterPosition(this.startPosition), true);
} else {
this._setDecorationIndex(this.nextIndex(this.decorationIndex), true);
}
}
private _revealFindScope(): void {
let findScope = this.getFindScope();
if (findScope) {
// Reveal the selection so user is reminded that 'selection find' is on.
this.editor.revealRangeInCenterIfOutsideViewport(findScope);
public setStartPosition(newStartPosition:EditorCommon.IEditorPosition): void {
this._startPosition = newStartPosition;
this.setCurrentFindMatch(null);
}
public setCurrentFindMatch(nextMatch:EditorCommon.IEditorRange): void {
let newCurrentDecorationId: string = null;
if (nextMatch) {
for (let i = 0, len = this._decorations.length; i < len; i++) {
let range = this._editor.getModel().getDecorationRange(this._decorations[i]);
if (nextMatch.equalsRange(range)) {
newCurrentDecorationId = this._decorations[i];
break;
}
}
}
}
private _setDecorationIndex(newIndex:number, moveCursor:boolean): void {
this.decorationIndex = newIndex;
this.editor.changeDecorations((changeAccessor: EditorCommon.IModelDecorationsChangeAccessor) => {
if (this.highlightedDecorationId !== null) {
changeAccessor.changeDecorationOptions(this.highlightedDecorationId, FindDecorations.createFindMatchDecorationOptions(false));
this.highlightedDecorationId = null;
}
if (moveCursor && this.decorationIndex >= 0 && this.decorationIndex < this.decorations.length) {
this.highlightedDecorationId = this.decorations[this.decorationIndex];
changeAccessor.changeDecorationOptions(this.highlightedDecorationId, FindDecorations.createFindMatchDecorationOptions(true));
}
});
if (moveCursor && this.decorationIndex >= 0 && this.decorationIndex < this.decorations.length) {
let range = this.editor.getModel().getDecorationRange(this.decorations[this.decorationIndex]);
this.editor.setSelection(range);
if (this._highlightedDecorationId !== null || newCurrentDecorationId !== null) {
this._editor.changeDecorations((changeAccessor: EditorCommon.IModelDecorationsChangeAccessor) => {
if (this._highlightedDecorationId !== null) {
changeAccessor.changeDecorationOptions(this._highlightedDecorationId, FindDecorations.createFindMatchDecorationOptions(false));
this._highlightedDecorationId = null;
}
if (newCurrentDecorationId !== null) {
this._highlightedDecorationId = newCurrentDecorationId;
changeAccessor.changeDecorationOptions(this._highlightedDecorationId, FindDecorations.createFindMatchDecorationOptions(true));
}
});
}
}
......@@ -137,62 +94,26 @@ export class FindDecorations implements Lifecycle.IDisposable {
options: FindDecorations.createFindScopeDecorationOptions()
});
}
let tmpDecorations = this.editor.deltaDecorations(this._allDecorations(), newDecorations);
let tmpDecorations = this._editor.deltaDecorations(this._allDecorations(), newDecorations);
if (findScope) {
this.findScopeDecorationId = tmpDecorations.shift();
this._findScopeDecorationId = tmpDecorations.shift();
} else {
this.findScopeDecorationId = null;
this._findScopeDecorationId = null;
}
this.decorations = tmpDecorations;
this.decorationIndex = -1;
this.highlightedDecorationId = null;
this._decorations = tmpDecorations;
this._highlightedDecorationId = null;
}
private _allDecorations(): string[] {
let result:string[] = [];
result = result.concat(this.decorations);
if (this.findScopeDecorationId) {
result.push(this.findScopeDecorationId);
result = result.concat(this._decorations);
if (this._findScopeDecorationId) {
result.push(this._findScopeDecorationId);
}
return result;
}
private indexAfterPosition(position:EditorCommon.IEditorPosition): number {
if (this.decorations.length === 0) {
return 0;
}
for (let i = 0, len = this.decorations.length; i < len; i++) {
let decorationId = this.decorations[i];
let r = this.editor.getModel().getDecorationRange(decorationId);
if (!r || r.startLineNumber < position.lineNumber) {
continue;
}
if (r.startLineNumber > position.lineNumber) {
return i;
}
if (r.startColumn < position.column) {
continue;
}
return i;
}
return 0;
}
private previousIndex(index:number): number {
if (this.decorations.length > 0) {
return (index - 1 + this.decorations.length) % this.decorations.length;
}
return 0;
}
private nextIndex(index:number): number {
if (this.decorations.length > 0) {
return (index + 1) % this.decorations.length;
}
return 0;
}
private static createFindMatchDecorationOptions(isCurrent:boolean): EditorCommon.IModelDecorationOptions {
return {
stickiness: EditorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
......
......@@ -157,7 +157,7 @@ export class SuggestController implements EditorCommon.IEditorContribution {
}
}
public hideSuggestWidget(): void {
public cancelSuggestWidget(): void {
if (this.widget) {
this.widget.cancel();
}
......@@ -186,6 +186,12 @@ export class SuggestController implements EditorCommon.IEditorContribution {
this.widget.selectPreviousPage();
}
}
public toggleSuggestionDetails(): void {
if (this.widget) {
this.widget.toggleDetails();
}
}
}
export class TriggerSuggestAction extends EditorAction {
......@@ -219,7 +225,7 @@ CommonEditorRegistry.registerEditorCommand(ACCEPT_SELECTED_SUGGESTION_CMD, weigh
});
CommonEditorRegistry.registerEditorCommand('hideSuggestWidget', weight, { primary: KeyCode.Escape }, true, CONTEXT_SUGGEST_WIDGET_VISIBLE, (ctx, editor, args) => {
const controller = SuggestController.getSuggestController(editor);
controller.hideSuggestWidget();
controller.cancelSuggestWidget();
});
CommonEditorRegistry.registerEditorCommand('selectNextSuggestion', weight, { primary: KeyCode.DownArrow }, true, CONTEXT_SUGGEST_WIDGET_VISIBLE, (ctx, editor, args) => {
const controller = SuggestController.getSuggestController(editor);
......@@ -237,4 +243,8 @@ CommonEditorRegistry.registerEditorCommand('selectPrevPageSuggestion', weight, {
const controller = SuggestController.getSuggestController(editor);
controller.selectPrevPageSuggestion();
});
CommonEditorRegistry.registerEditorCommand('toggleSuggestionDetails', weight, { primary: KeyMod.CtrlCmd | KeyCode.Space, mac: { primary: KeyMod.WinCtrl | KeyCode.Space } }, true, CONTEXT_SUGGEST_WIDGET_VISIBLE, (ctx, editor, args) => {
const controller = SuggestController.getSuggestController(editor);
controller.toggleSuggestionDetails();
});
EditorBrowserRegistry.registerEditorContribution(SuggestController);
......@@ -11,34 +11,7 @@ import {Selection} from 'vs/editor/common/core/selection';
import {Cursor} from 'vs/editor/common/controller/cursor';
import EditorCommon = require('vs/editor/common/editorCommon');
import {IMode} from 'vs/editor/common/modes';
import {CommonEditorConfiguration, ICSSConfig} from 'vs/editor/common/config/commonEditorConfig';
export class MockConfiguration extends CommonEditorConfiguration {
constructor(opts:any) {
super(opts);
}
protected getOuterWidth(): number {
return 100;
}
protected getOuterHeight(): number {
return 100;
}
protected readConfiguration(editorClassName: string, fontFamily: string, fontSize: number, lineHeight: number): ICSSConfig {
// Doesn't really matter
return {
typicalHalfwidthCharacterWidth: 10,
typicalFullwidthCharacterWidth: 20,
maxDigitWidth: 10,
lineHeight: 20,
font: 'mockFont',
fontSize: 20
};
}
}
import {MockConfiguration} from 'vs/editor/test/common/mocks/mockConfiguration';
export function testCommand(
lines: string[],
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册