Skip to content

Commit

Permalink
add custom mark names
Browse files Browse the repository at this point in the history
will be needed for vim style marks
  • Loading branch information
sdsand committed Nov 30, 2021
1 parent 3de1484 commit 753fc30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/lib/mark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ test("make mark, kill mark", () => {
m = Marks.getMark(Marks.createMark(0));
expect(m?.location).toEqual(0);

let o = Marks.createMark(l, "gaming_corporate_office");
expect(o).toEqual("gaming_corporate_office");

// delete when it exists and doesnt
expect(Marks.removeMark(Marks.createMark())).toEqual(true);
expect(Marks.removeMark("owo")).toEqual(true);
});
Expand Down
10 changes: 5 additions & 5 deletions src/lib/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const makeMarkList = (): MarkList => {
* @param location: where in the text to place the mark, positive int, optinal.
* @return a mark, the marks location field is set to location if location passed is a positive int, -1 otherwise
*/
const createMark = (location?: number): string => {
const createMark = (location?: number, name?: string): string => {
const m = {
location: location !== undefined && location >= 0 ? location : -1,
fixed: false,
};
const name = (Math.random() + 1).toString(36).substring(2);
markTable.set(name, m);
return name;
const n = name || (Math.random() + 1).toString(36).substring(2);
markTable.set(n, m);
return n;
};

/** remove a mark
Expand Down Expand Up @@ -111,7 +111,7 @@ const makeMarkList = (): MarkList => {
};

interface MarkList {
createMark: (location?: number) => string;
createMark: (location?: number, name?: string) => string;
removeMark: (name: string) => boolean;
getMark: (name: string) => Mark | undefined;
whereIs: (name: string) => number | undefined;
Expand Down

0 comments on commit 753fc30

Please sign in to comment.