message: If already magic comment in first line, replace instead of just insert new one
diff: @@ -28,7 +28,7 @@ export class TeXMagician {
  currentFolder = currentFolder.substring(i)
  // replace each '/foldername/' in path with '/../'
  currentFolder = currentFolder.replace(/[^/]+/g, '..')
  - return './' + currentFolder + file
  + return ('./' + currentFolder + file).replace(/^\.\/\.\./, '..')
  }
  addroot() {
  @@ -39,15 +39,22 @@ export class TeXMagician {
  })
  vscode.window.showQuickPick(displayFiles).then(val => {
  const editor = vscode.window.activeTextEditor
  - if (val != null && editor != null) {
  + if (!(val && editor)) {
  + return
  + }
  const relativePath = this.getRelativePath(val.filePath, editor.document.fileName)
  - const edits = [vscode.TextEdit.insert(new vscode.Position(0, 0), `% !TeX root = ${relativePath}${EOL}`)]
  + const magicComment = `% !TeX root = ${relativePath}`
  + const line0 = editor.document.lineAt(0).text
  + const edits = [(line0.match(/^\s*%\s*!TeX root/gmi)) ?
  + vscode.TextEdit.replace(new vscode.Range(0, 0, 0, line0.length), magicComment)
  + :
  + vscode.TextEdit.insert(new vscode.Position(0, 0), magicComment + EOL)
  + ]
  // Insert the text
  const uri = editor.document.uri
  const edit = new vscode.WorkspaceEdit()
  edit.set(uri, edits)
  vscode.workspace.applyEdit(edit)
  - }
  })
  })
  }
  