file.js 1.66 KB
Newer Older
1 2 3 4 5 6 7 8
import * as types from '../mutation_types';
import { findIndexOfFile } from '../utils';

export default {
  [types.SET_FILE_ACTIVE](state, { file, active }) {
    Object.assign(file, {
      active,
    });
9 10 11 12

    Object.assign(state, {
      selectedFile: file,
    });
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  },
  [types.TOGGLE_FILE_OPEN](state, file) {
    Object.assign(file, {
      opened: !file.opened,
    });

    if (file.opened) {
      state.openFiles.push(file);
    } else {
      state.openFiles.splice(findIndexOfFile(state.openFiles, file), 1);
    }
  },
  [types.SET_FILE_DATA](state, { data, file }) {
    Object.assign(file, {
      blamePath: data.blame_path,
      commitsPath: data.commits_path,
      permalink: data.permalink,
      rawPath: data.raw_path,
      binary: data.binary,
      html: data.html,
33
      renderError: data.render_error,
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    });
  },
  [types.SET_FILE_RAW_DATA](state, { file, raw }) {
    Object.assign(file, {
      raw,
    });
  },
  [types.UPDATE_FILE_CONTENT](state, { file, content }) {
    const changed = content !== file.raw;

    Object.assign(file, {
      content,
      changed,
    });
  },
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  [types.SET_FILE_LANGUAGE](state, { file, fileLanguage }) {
    Object.assign(file, {
      fileLanguage,
    });
  },
  [types.SET_FILE_EOL](state, { file, eol }) {
    Object.assign(file, {
      eol,
    });
  },
  [types.SET_FILE_POSITION](state, { file, editorRow, editorColumn }) {
    Object.assign(file, {
      editorRow,
      editorColumn,
    });
  },
65 66 67 68 69 70
  [types.DISCARD_FILE_CHANGES](state, file) {
    Object.assign(file, {
      content: '',
      changed: false,
    });
  },
71 72 73
  [types.CREATE_TMP_FILE](state, { file, parent }) {
    parent.tree.push(file);
  },
74
};