Skip to content

Commit 5e11d1f

Browse files
committed
removed char plus added char should yield neutral char
1 parent cd11c72 commit 5e11d1f

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"build": "ng build",
88
"test": "ng test",
99
"lint": "ng lint",
10-
"e2e": "ng e2e"
10+
"e2e": "ng e2e",
11+
"build-keyboard": "ng build angular-keyboard",
12+
"watch-keyboard": "ng build angular-keyboard --watch"
1113
},
1214
"private": true,
1315
"dependencies": {

projects/angular-keyboard/README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,17 @@ It's not an easy task to build this lib, so there are some pending issues we're
5757

5858
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.1.3.
5959

60-
## Code scaffolding
6160

62-
Run `ng generate component component-name --project angular-keyboard` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project angular-keyboard`.
63-
> Note: Don't forget to add `--project angular-keyboard` or else it will be added to the default project in your `angular.json` file.
61+
## Development
6462

65-
## Build
63+
Run `ng build angular-keyboard --watch` from the repository root, then run `npm start`. That way you can test the behaviour of your library easily.
6664

67-
Update the package version in the `package.json` in this folder. Run `ng build angular-keyboard` to build the project. The build artifacts will be stored in the `dist/` directory.
65+
## Build and Publish
6866

69-
## Publishing
67+
Update the package version in the `package.json` in this folder. Run `ng build angular-keyboard` to build the project. The build artifacts will be stored in the `dist/` directory.
7068

71-
After building your library with `ng build angular-keyboard`, go to the dist folder `cd dist/angular-keyboard` and run `npm publish`.
69+
After building your library, go to the dist folder `cd dist/angular-keyboard` and run `npm publish`.
7270

7371
## Running unit tests
7472

7573
Run `ng test angular-keyboard` to execute the unit tests via [Karma](https://karma-runner.github.io).
76-
77-
## Further help
78-
79-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

projects/angular-keyboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@taskbase/angular-keyboard",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"peerDependencies": {
55
"@angular/common": "^8.1.3",
66
"@angular/core": "^8.1.3"

projects/angular-keyboard/src/lib/fake-input/fake-input.component.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ export class FakeInputComponent implements OnInit, OnDestroy {
147147
if (action instanceof Function) {
148148
action();
149149
} else {
150-
const isChar = next.length === 1; // could also be unhandlet command like shift, so we need to check here.
151-
if (next.length === 1) {
150+
const isChar = next.length === 1; // could also be unhandled command like shift, so we need to check here.
151+
if (isChar) {
152152
this.insertChar(next);
153153
}
154154
}
@@ -185,40 +185,62 @@ export class FakeInputComponent implements OnInit, OnDestroy {
185185
newChar,
186186
...this.chars.slice(this.cursorPos, this.chars.length)
187187
];
188-
this.cursor = {
189-
index: this.cursorPos,
190-
side: Side.RIGHT
191-
};
192188

193-
this.cleanSuggestions();
189+
this.cleanSuggestionsAndMoveCursor();
194190
}
195191

196-
cleanSuggestions() {
192+
cleanSuggestionsAndMoveCursor() {
193+
let moveCursor = true;
197194
if (this.suggestionMode) {
198195
const updatedChars = [];
199196
// tslint:disable-next-line
200197
for (let i = 0; i < this.chars.length; i++) {
201198
const char = this.chars[i];
202199
const nextChar = this.chars[i + 1];
200+
const previousChar = this.chars[i - 1];
203201
if (
204202
char.charState === CharState.ADDED &&
205203
nextChar != null && nextChar.charState === CharState.REMOVED &&
206204
char.char === nextChar.char
207205
) {
208-
// this and the next char should be removed.
206+
207+
// ADDED + REMOVED == normal char
209208
updatedChars.push({
210209
...char,
211210
charState: null
212211
});
213212

214213
// Skip the next index.
215214
i = i + 1;
215+
} else if (
216+
char.charState === CharState.ADDED &&
217+
previousChar != null && previousChar.charState === CharState.REMOVED &&
218+
char.char === previousChar.char
219+
) {
220+
221+
// remove the "REMOVED" char
222+
updatedChars.pop();
223+
224+
// REMOVED + ADDED == normal char
225+
updatedChars.push({
226+
...char,
227+
charState: null
228+
});
229+
230+
moveCursor = false;
231+
216232
} else {
217233
updatedChars.push(char);
218234
}
219235
}
220236
this.chars = updatedChars;
221237
}
238+
if (moveCursor === true) {
239+
this.cursor = {
240+
index: this.cursorPos,
241+
side: Side.RIGHT
242+
};
243+
}
222244
}
223245

224246
deleteChar(charIndex: number) {

0 commit comments

Comments
 (0)