Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
0.0.3 Improvement
Browse files Browse the repository at this point in the history
Quick-edit is also available without whole word selection.
  • Loading branch information
EricSmekens committed Nov 9, 2014
1 parent 73a4327 commit ea92f08
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 40 deletions.
46 changes: 23 additions & 23 deletions KO Example/index.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<html>
<head>
<script>
// Here's my data model
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);

this.fullName = ko.computed(function() {
// Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
return this.firstName() + " " + this.lastName();
}, this);

};
<head>
<script>
// Here's my data model
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);

ViewModel();
testFunction();
ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work
</script>
</head>
this.fullName = ko.computed(function() {
// Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
return this.firstName() + " " + this.lastName();
}, this);

<body>
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello <span data-bind="value: fullName"> </span>!</h2>
</body>
};

ViewModel();
testFunction();
ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work
</script>
</head>

<body>
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello <span data-bind="value: fullName"> </span>!</h2>
</body>
</html>
11 changes: 6 additions & 5 deletions KOUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* Used as an example. Kudo's to Adobe for releasing and creating Brackets open-source. */

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, CodeMirror */
/*global define, $, brackets */

/**
* Set of utilities for simple parsing of KO functions.
Expand All @@ -20,7 +20,8 @@ define(function (require, exports, module) {
FileUtils = brackets.getModule("file/FileUtils"),
PerfUtils = brackets.getModule("utils/PerfUtils"),
ProjectManager = brackets.getModule("project/ProjectManager"),
StringUtils = brackets.getModule("utils/StringUtils");
StringUtils = brackets.getModule("utils/StringUtils"),
_codeMirror = brackets.getModule("thirdparty/CodeMirror2/lib/codemirror")

/**
* Tracks dirty documents between invocations of findMatchingFunctions.
Expand Down Expand Up @@ -71,8 +72,8 @@ define(function (require, exports, module) {
// the end offset for the function (the closing "}"). Returns the position one past the
// close brace. Properly ignores braces inside comments, strings, and regexp literals.
function _getFunctionEndOffset(text, offsetStart) {
var mode = CodeMirror.getMode({}, "javascript");
var state = CodeMirror.startState(mode), stream, style, token;
var mode = _codeMirror.getMode({}, "javascript");
var state = _codeMirror.startState(mode), stream, style, token;
var curOffset = offsetStart, length = text.length, blockCount = 0, lineStart;
var foundStartBrace = false;

Expand All @@ -90,7 +91,7 @@ define(function (require, exports, module) {
if (lineEnd === -1) {
lineEnd = length;
}
stream = new CodeMirror.StringStream(text.slice(curOffset, lineEnd));
stream = new _codeMirror.StringStream(text.slice(curOffset, lineEnd));
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013 Eric Smekens
Copyright (c) 2014 Eric Smekens

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
KnockoutJS-brackets 0.0.2
KnockoutJS-brackets 0.0.3
===================

Knockout extension for brackets. It's currently work-in-progress.
Ideas, contributions and any other support are welcome! :)


## Release notes

### 0.0.3
* Tested for brackets 1.0.0. Older versions of brackets may work, but I set 1.0.0 as lowest requirement. You can still use 0.0.2.
* Removed deprecated function usages.
* Single cursor quick-edit inside a computed name now works.

### 0.0.2
* ko.computed quick-edit works for names with numbers and underscores as well.

Expand All @@ -15,21 +19,18 @@ Ideas, contributions and any other support are welcome! :)
* Quick-edit for ko.computed. (Not works with numbers in computed name and only works when you fully select the computed's name.)



What is currently working
-----------
Quick-edit for ko.computed.
(Only works when you fully select the computed's name.)
This feature will be extended in next versions.


Currently planning to implement:
-----------
*Unit-tests.
*More refactoring and improving current ko.computed functionality.
* Unit-tests.
* More refactoring and improving current ko.computed functionality.

Quick-edit for:
* better quick edit for ko.computed
* ko.observable ?
* subscribes ?

Expand Down
14 changes: 13 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ define(function (require, exports, module) {
* Return the selected string.
*/
function _getComputedName(hostEditor, pos) {
return hostEditor._codeMirror.getSelection();
var A1 = pos.line;
var A2 = pos.ch;

var B1 = hostEditor._codeMirror.findWordAt({line: A1, ch: A2}).anchor.ch;
var B2 = hostEditor._codeMirror.findWordAt({line: A1, ch: A2}).head.ch;

var computedName = hostEditor._codeMirror.getRange({line: A1,ch: B1}, {line: A1,ch: B2});
if (computedName.match(/[a-zA-Z]\w+/g)) {
return computedName;
} else {
//Fallback, didn't get computed name, so just get the selection instead.
return hostEditor._codeMirror.getSelection();
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "ericsmekens.knockoutjs",
"title": "KnockoutJS for Brackets",
"description": "Adding knockout quickedits to brackets (only basic quick-edit for ko.computed at the moment.)",
"description": "Adding knockout quickedits to brackets (only basic quick-edit for ko.computed at the moment. Ideas are welcome!)",
"homepage": "https://github.com/EricSmekens/KnockoutJS-brackets",
"version": "0.0.2",
"version": "0.0.3",
"author": "Eric Smekens (https://github.com/EricSmekens)",
"license": "MIT",
"engines": {
"brackets": ">=0.34.0"
"brackets": ">=1.0.0"
}
}

0 comments on commit ea92f08

Please sign in to comment.