@import '../constants/animations';
@import '../constants/dimensions';
@import '../constants/fonts';

.editor {
  box-sizing: border-box;
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-columns: 100%;

  &[data-editor-type='password'] .CodeMirror-line {
    -webkit-text-security: disc;

    // NOTE: <span cm-text> appears with hidden character when editor is empty
    [cm-text=''],
    .CodeMirror-widget {
      -webkit-text-security: none;
    }
  }

  .editor__container {
    height: 100%;
    width: 100%;
    position: relative;
  }

  .CodeMirror {
    z-index: 0; // Because some children have z-index ~5
    line-height: 1.4em;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
  }

  .editor__toolbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    border-top: 1px solid var(--hl-md);
    height: @line-height-xs;
    font-size: @font-size-sm;

    input {
      font-family: @font-monospace;
      margin-right: 0;
      width: 100%;
      margin-left: @padding-md;
    }

    button {
      color: var(--hl);
      padding: @padding-xs @padding-md;
      height: 100%;
    }
  }

  .CodeMirror {
    height: 100% !important;
    width: 100%;
    box-sizing: border-box;
    font-family: @font-monospace;

    .CodeMirror-line * {
      font-variant-ligatures: var(--font-ligatures);
    }
  }

  .CodeMirror,
  .cm-s-seti.CodeMirror, // Hack because seti theme is dumb
  .CodeMirror-gutters,
  .CodeMirror-scrollbar-filler,
  .CodeMirror-gutter-filler {
    // Let the background behind show through
    background-color: transparent !important;
    border: 0;
  }

  .CodeMirror-linenumber {
    color: var(--hl-xl) !important;
  }

  .CodeMirror-foldgutter-folded,
  .CodeMirror-foldgutter-open {
    font-size: 1.2em;
    font-family: 'Times New Roman', serif;
    margin-left: -2px;
  }

  .CodeMirror-guttermarker-subtle {
    color: var(--hl-lg);
    &:hover {
      color: var(--hl);
    }
  }

  .CodeMirror-gutters {
    background-color: transparent;
  }

  .CodeMirror-scroll {
    cursor: text; // Show text cursor everywhere (not just in .Codemirror-lines)
  }

  .CodeMirror-lines {
    // Scroll past the end
    padding-bottom: 30px;
  }

  .CodeMirror-placeholder {
    color: var(--hl-lg);
  }

  .CodeMirror-lint-marker-error {
    width: 100%;
    height: 1em;
    display: flex;
    background: none;
    text-align: center;

    &::after {
      color: var(--color-danger);
      text-align: center;
      width: 100%;
      font-size: 0.7em; // because the circle is so large
      content: '⬤';
    }
  }

  .CodeMirror-activeline-gutter,
  .CodeMirror-activeline-background {
    background-color: transparent;
  }

  &:not(.editor--readonly) .CodeMirror-focused .CodeMirror-activeline-gutter,
  &:not(.editor--readonly) .CodeMirror-focused .CodeMirror-activeline-background {
    background-color: var(--hl-xs);
  }

  &.editor--readonly .CodeMirror-cursors {
    visibility: hidden;
  }

  &.editor--dynamic-height {
    .CodeMirror {
      position: static;
    }

    .CodeMirror-lines {
      padding-bottom: 0.5em;
    }
  }
}
