Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Utilized pragmaUtil Functions for kb.json file

* Typo fix

* Added universalKeybindings setting
  • Loading branch information
njkevlani authored and shanalikhan committed May 6, 2019
1 parent 4e1d08d commit a387c23
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/pragmaUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ export default class PragmaUtil {
* Remove @sync-ignore settings before upload.
*
* @static
* @param {string} settingsContent
* @param {string} fileContent
* @returns {string}
* @memberof PragmaUtil
*/
public static processBeforeUpload(settingsContent: string): string {
const lines = settingsContent.split("\n");
public static processBeforeUpload(fileContent: string): string {
const lines = fileContent.split("\n");
let osMatch: RegExpMatchArray;
let osFromPragma: string;

Expand Down Expand Up @@ -258,7 +258,7 @@ export default class PragmaUtil {
parsedLines.push(this.toggleComments(currentLine, shouldComment));
}

const opensCurlyBraces = /".+"\s*:\s*{/.test(currentLine);
const opensCurlyBraces = /{/.test(currentLine);
const opensBrackets = /".+"\s*:\s*\[/.test(currentLine);

let openedBlock = opensCurlyBraces || opensBrackets;
Expand Down
1 change: 1 addition & 0 deletions src/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ export class CustomSettings {
public askGistName: boolean = false;
public customFiles: { [key: string]: string } = {};
public hostName: string = null;
public universalKeybindings: boolean = false;
}
45 changes: 30 additions & 15 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,20 @@ export class Sync {
if (snippetFile.content !== "") {
if (snippetFile.fileName === env.FILE_KEYBINDING_NAME) {
snippetFile.gistName =
env.OsType === OsType.Mac
env.OsType === OsType.Mac &&
!customSettings.universalKeybindings
? env.FILE_KEYBINDING_MAC
: env.FILE_KEYBINDING_DEFAULT;
}
allSettingFiles.push(snippetFile);
}
}

if (snippetFile.fileName === env.FILE_SETTING_NAME) {
if (
snippetFile.fileName === env.FILE_SETTING_NAME ||
snippetFile.fileName === env.FILE_KEYBINDING_MAC ||
snippetFile.fileName === env.FILE_KEYBINDING_DEFAULT
) {
try {
snippetFile.content = PragmaUtil.processBeforeUpload(
snippetFile.content
Expand Down Expand Up @@ -485,17 +490,23 @@ export class Sync {
);
updatedFiles.push(f);
} else if (gistName.indexOf(".") > -1) {
if (
env.OsType === OsType.Mac &&
gistName === env.FILE_KEYBINDING_DEFAULT
) {
return;
}
if (
env.OsType !== OsType.Mac &&
gistName === env.FILE_KEYBINDING_MAC
) {
return;
if (customSettings.universalKeybindings) {
if (gistName === env.FILE_KEYBINDING_MAC) {
return;
}
} else {
if (
env.OsType === OsType.Mac &&
gistName === env.FILE_KEYBINDING_DEFAULT
) {
return;
}
if (
env.OsType !== OsType.Mac &&
gistName === env.FILE_KEYBINDING_MAC
) {
return;
}
}
const f: File = new File(
gistName,
Expand Down Expand Up @@ -583,7 +594,7 @@ export class Sync {
file.gistName === env.FILE_KEYBINDING_MAC
) {
let test: string = "";
env.OsType === OsType.Mac
env.OsType === OsType.Mac && !customSettings.universalKeybindings
? (test = env.FILE_KEYBINDING_MAC)
: (test = env.FILE_KEYBINDING_DEFAULT);
if (file.gistName !== test) {
Expand All @@ -604,7 +615,11 @@ export class Sync {
);
}

if (file.gistName === env.FILE_SETTING_NAME) {
if (
file.gistName === env.FILE_SETTING_NAME ||
file.gistName === env.FILE_KEYBINDING_MAC ||
file.gistName === env.FILE_KEYBINDING_DEFAULT
) {
const localContent = await FileService.ReadFile(filePath);
content = PragmaUtil.processBeforeWrite(
localContent,
Expand Down

0 comments on commit a387c23

Please sign in to comment.