{ "scope": "source.js", "completions": [ { "trigger": "description-Date", "contents": "/*\n\tDescription:\n\tCreates a JavaScript Date instance that represents a single moment in time. Date objects are based on a time value that is the number of milliseconds since 1 January, 1970 UTC.\n\n\tSyntax:\n\tnew Date();\n\tnew Date(value);\n\tnew Date(dateString);\n\tnew Date(year, month, day, hour, minute, second, millisecond);\n*/" }, { "trigger": "description-Date.now()", "contents": "/*\n\tDescription:\n\tThe Date.now() method returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.\n\n\tSyntax:\n\tvar timeInMs = Date.now();\n*/" } ] }
if forward: if view.substr(pos) in ws and view.substr(pos + 1) in ws: classes = sublime.CLASS_WORD_START | sublime.CLASS_PUNCTUATION_START | sublime.CLASS_LINE_END else: if view.substr(pos - 1) in ws and view.substr(pos - 2) in ws: classes = sublime.CLASS_WORD_END | sublime.CLASS_PUNCTUATION_END | sublime.CLASS_LINE_START
if forward: self.view.run_command('right_delete') else: self.view.run_command('left_delete')
duplicate_line.py
1 2 3 4 5 6 7 8 9 10 11
import sublime, sublime_plugin
classDuplicateLineCommand(sublime_plugin.TextCommand): defrun(self, edit): for region in self.view.sel(): if region.empty(): line = self.view.line(region) line_contents = self.view.substr(line) + '\n' self.view.insert(edit, line.begin(), line_contents) else: self.view.insert(edit, region.begin(), self.view.substr(region))
classIncreaseFontSizeCommand(sublime_plugin.ApplicationCommand): defrun(self): s = sublime.load_settings("Preferences.sublime-settings") current = s.get("font_size", 10)
if current >= 36: current += 4 elif current >= 24: current += 2 else: current += 1
if current > 128: current = 128 s.set("font_size", current)
classDecreaseFontSizeCommand(sublime_plugin.ApplicationCommand): defrun(self): s = sublime.load_settings("Preferences.sublime-settings") current = s.get("font_size", 10) # current -= 1
if current >= 40: current -= 4 elif current >= 26: current -= 2 else: current -= 1
if current < 8: current = 8 s.set("font_size", current)
classSetMarkCommand(sublime_plugin.TextCommand): defrun(self, edit): mark = [s for s in self.view.sel()] self.view.add_regions("mark", mark, "mark", "dot", sublime.HIDDEN | sublime.PERSISTENT)
classTrimTrailingWhiteSpaceCommand(sublime_plugin.TextCommand): defrun(self, edit): trailing_white_space = self.view.find_all("[\t ]+$") trailing_white_space.reverse() for r in trailing_white_space: self.view.erase(edit, r)
classTrimTrailingWhiteSpace(sublime_plugin.EventListener): defon_pre_save(self, view): if view.settings().get("trim_trailing_white_space_on_save") == True: view.run_command("trim_trailing_white_space")
In JavaScript, as in most object-oriented programming languages, this is a special keyword that is used within methods to refer to the object on which a method is being invoked.
The this keyword is relative to the execution context, not the declaration context.
grayscale = function (pixels) { var d = pixels.data; for (var i = 0; i < d.length; i += 4) { var r = d[i]; var g = d[i + 1]; var b = d[i + 2]; d[i] = d[i + 1] = d[i + 2] = (r+g+b)/3; } return pixels; };
sepia = function (pixels) { var d = pixels.data; for (var i = 0; i < d.length; i += 4) { var r = d[i]; var g = d[i + 1]; var b = d[i + 2]; d[i] = (r * 0.393)+(g * 0.769)+(b * 0.189); // red d[i + 1] = (r * 0.349)+(g * 0.686)+(b * 0.168); // green d[i + 2] = (r * 0.272)+(g * 0.534)+(b * 0.131); // blue } return pixels; };
red = function (pixels) { var d = pixels.data; for (var i = 0; i < d.length; i += 4) { var r = d[i]; var g = d[i + 1]; var b = d[i + 2]; d[i] = (r+g+b)/3; // 红色通道取平均值 d[i + 1] = d[i + 2] = 0; // 绿色通道和蓝色通道都设为0 } return pixels; };
brightness = function (pixels, delta) { var d = pixels.data; for (var i = 0; i < d.length; i += 4) { d[i] += delta; // red d[i + 1] += delta; // green d[i + 2] += delta; // blue } return pixels; };
function doBack() {
if (canvas.width > 0 && canvas.height > 0) {
context.putImageData(originImageData, 0, 0);
}
}
var grayscale = function (pixels) {
var d = pixels.data;
for (var i = 0; i < d.length; i += 4) {
var r = d[i];
var g = d[i + 1];
var b = d[i + 2];
d[i] = d[i + 1] = d[i + 2] = (r+g+b)/3;
}
return pixels;
};
var sepia = function (pixels) {
var d = pixels.data;
for (var i = 0; i < d.length; i += 4) {
var r = d[i];
var g = d[i + 1];
var b = d[i + 2];
d[i] = (r * 0.393)+(g * 0.769)+(b * 0.189); // red
d[i + 1] = (r * 0.349)+(g * 0.686)+(b * 0.168); // green
d[i + 2] = (r * 0.272)+(g * 0.534)+(b * 0.131); // blue
}
return pixels;
};
var red = function (pixels) {
var d = pixels.data;
for (var i = 0; i < d.length; i += 4) {
var r = d[i];
var g = d[i + 1];
var b = d[i + 2];
d[i] = (r+g+b)/3; // 红色通道取平均值
d[i + 1] = d[i + 2] = 0; // 绿色通道和蓝色通道都设为0
}
return pixels;
};
var brightness = function (pixels, delta) {
var d = pixels.data;
for (var i = 0; i < d.length; i += 4) {
d[i] += delta; // red
d[i + 1] += delta; // green
d[i + 2] += delta; // blue
}
return pixels;
};
var invert = function (pixels) {
var d = pixels.data;
for (var i = 0; i < d.length; i += 4) {
d[i] = 255 - d[i];
d[i+1] = 255 - d[i + 1];
d[i+2] = 255 - d[i + 2];
}
return pixels;
};
function doGrayscale() {
doWhat(grayscale);
}
function doSepia() {
doWhat(sepia);
}
function doRed() {
doWhat(red);
}
function doBrightness() {
var delta = parseInt(document.getElementById("delta").value, 10);
doWhat(brightness, delta);
}