最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why does IntelliJ keep removing backticks from this JavaScript template string? - Stack Overflow

programmeradmin3浏览0评论

I want to put "backticks" around my template strings.

IntelliJ keeps removing them every time I try the wrap them around the string.

Anyone's got a clue why its happening and how to solve this?

I added a little code snippet of my .vue file where the problem occurred. Imagine html, js and css written down in one component (.vue) file, separated by unique tags (template, script and style tag). I am using a german keyboard layout with the Mac OS X 10.5+ keymap.

import axios from "axios";
import 'vue-animate/dist/vue-animate.min.css';

export default {
  name: 'hello',
  data () {
    return {
      msg: `Service is <strong>ONLINE</strong> and <strong>READY</strong> to operate`,
      clicked: false,
      iconURL:"./../../static/img/meditate.svg",
      meditationAction: this.activateMeditation,
      backgroundImage: "",
      room:"Bad"

    }
  },
  methods:{
      activateMeditation () {
          this.clicked = !this.clicked;

          axios.get(`http://localhost:5005/${this.room}/shuffle/on`).then(response => {
              console.info("SUCCESSFULLY ACTIVATED SHUFFLE");

            axios.get(`http://localhost:5005/${this.room}/volume/20`).then(response => {
              console.info("SUCCESSFULLY SET VOLUME TO 20");

              axios.get("http://localhost:5005/bad/sleep/900").then(response => {
                console.info("SUCCESSFULLY SET SLEEP TIME TO 15 MINUTES");

                axios.get("http://localhost:5005/bad/playlist/med").then(response => {
                  console.info("SUCCESSFULLY SET PLAYLIST TO MED");
                  this.iconURL = "./../../static/img/stop.svg";
                  this.meditationAction = this.pausePlayback;

                  axios.get("http://localhost:5005/bad/state").then(response => {
                    console.info("SUCCESSFULLY RETRIEVED STATE");
                    console.log(response);
                    //FIXME: USE IMAGE OF CURRENT TRACK INSTEAD OF NEXT TRACK
                    this.backgroundImage = response.data.nextTrack.absoluteAlbumArtUri;
                  })
                  .catch((error)=>{
                    console.log(error);
                  });

                })
                .catch((error)=>{
                  console.log(error);
                });

              })
              .catch((error)=>{
                console.log(error);
              });

            })
            .catch((error)=>{
              console.log(error);
            });

          })
          .catch((error)=>{
            console.log(error);
            this.iconURL = "./../../static/img/attention.svg";
            this.meditationAction = this.resetButton;
          });


      },

    pausePlayback() {

      axios.get("http://localhost:5005/bad/pause").then(response => {
        console.info("SUCCESSFULLY PAUSED PLAYBACK");
        this.iconURL = "./../../static/img/meditate.svg";
        this.meditationAction = this.activateMeditation;
        this.backgroundImage = "";
      })
      .catch((error)=>{
        console.log(error);
      });

    },

    resetButton() {

      this.iconURL = "./../../static/img/meditate.svg";
      this.meditationAction = this.activateMeditation;

    }



  }
}
 * {

    box-sizing: border-box;
  }

  .logo {
    max-width:50%;
  }

  .svg {
    height:5em;
    z-index:100;
  }

  .option .svg .st0 {
    fill: white;
    stroke: white;
  }

  .options__container {
    display:flex;
    justify-content: center;
    align-items: center;
    width:100%;


  }

  .option {

    display:flex;
    justify-content: center;
    align-items: center;
    height:3em;
    width:3em;

    position:relative;

    background-size:cover;

    padding:3em;
    border-radius:100%;
    background-color:white;
    border-top:3px solid black;
    border-bottom:5px solid #303030;
    border-left:3px solid black;
    border-right:7px solid #303030;



    transition: all 300ms ease-in;

  }

  .option__background-image {


    position:absolute;
    background-color:white;
    opacity:0.8;
    top:0;
    left:0;
    height:100%;
    width:100%;
    border-radius: 100%;
  }

  .option:hover {

    border:3px solid black;

  }
  <div class="hello">
    <img class="logo" src=".png"/>
    <h2 v-html="msg"></h2>
    <div class="options__container">
      <a class="option" v-on:click="meditationAction" v-bind:class="{'animated flash' : clicked}" :style="{backgroundImage: 'url(' + backgroundImage +')'}" >
        <div class="option__background-image" ></div>
        <img class="svg" :src=iconURL>
      </a>
    </div>
  </div>

I want to put "backticks" around my template strings.

IntelliJ keeps removing them every time I try the wrap them around the string.

Anyone's got a clue why its happening and how to solve this?

I added a little code snippet of my .vue file where the problem occurred. Imagine html, js and css written down in one component (.vue) file, separated by unique tags (template, script and style tag). I am using a german keyboard layout with the Mac OS X 10.5+ keymap.

import axios from "axios";
import 'vue-animate/dist/vue-animate.min.css';

export default {
  name: 'hello',
  data () {
    return {
      msg: `Service is <strong>ONLINE</strong> and <strong>READY</strong> to operate`,
      clicked: false,
      iconURL:"./../../static/img/meditate.svg",
      meditationAction: this.activateMeditation,
      backgroundImage: "",
      room:"Bad"

    }
  },
  methods:{
      activateMeditation () {
          this.clicked = !this.clicked;

          axios.get(`http://localhost:5005/${this.room}/shuffle/on`).then(response => {
              console.info("SUCCESSFULLY ACTIVATED SHUFFLE");

            axios.get(`http://localhost:5005/${this.room}/volume/20`).then(response => {
              console.info("SUCCESSFULLY SET VOLUME TO 20");

              axios.get("http://localhost:5005/bad/sleep/900").then(response => {
                console.info("SUCCESSFULLY SET SLEEP TIME TO 15 MINUTES");

                axios.get("http://localhost:5005/bad/playlist/med").then(response => {
                  console.info("SUCCESSFULLY SET PLAYLIST TO MED");
                  this.iconURL = "./../../static/img/stop.svg";
                  this.meditationAction = this.pausePlayback;

                  axios.get("http://localhost:5005/bad/state").then(response => {
                    console.info("SUCCESSFULLY RETRIEVED STATE");
                    console.log(response);
                    //FIXME: USE IMAGE OF CURRENT TRACK INSTEAD OF NEXT TRACK
                    this.backgroundImage = response.data.nextTrack.absoluteAlbumArtUri;
                  })
                  .catch((error)=>{
                    console.log(error);
                  });

                })
                .catch((error)=>{
                  console.log(error);
                });

              })
              .catch((error)=>{
                console.log(error);
              });

            })
            .catch((error)=>{
              console.log(error);
            });

          })
          .catch((error)=>{
            console.log(error);
            this.iconURL = "./../../static/img/attention.svg";
            this.meditationAction = this.resetButton;
          });


      },

    pausePlayback() {

      axios.get("http://localhost:5005/bad/pause").then(response => {
        console.info("SUCCESSFULLY PAUSED PLAYBACK");
        this.iconURL = "./../../static/img/meditate.svg";
        this.meditationAction = this.activateMeditation;
        this.backgroundImage = "";
      })
      .catch((error)=>{
        console.log(error);
      });

    },

    resetButton() {

      this.iconURL = "./../../static/img/meditate.svg";
      this.meditationAction = this.activateMeditation;

    }



  }
}
 * {

    box-sizing: border-box;
  }

  .logo {
    max-width:50%;
  }

  .svg {
    height:5em;
    z-index:100;
  }

  .option .svg .st0 {
    fill: white;
    stroke: white;
  }

  .options__container {
    display:flex;
    justify-content: center;
    align-items: center;
    width:100%;


  }

  .option {

    display:flex;
    justify-content: center;
    align-items: center;
    height:3em;
    width:3em;

    position:relative;

    background-size:cover;

    padding:3em;
    border-radius:100%;
    background-color:white;
    border-top:3px solid black;
    border-bottom:5px solid #303030;
    border-left:3px solid black;
    border-right:7px solid #303030;



    transition: all 300ms ease-in;

  }

  .option__background-image {


    position:absolute;
    background-color:white;
    opacity:0.8;
    top:0;
    left:0;
    height:100%;
    width:100%;
    border-radius: 100%;
  }

  .option:hover {

    border:3px solid black;

  }
  <div class="hello">
    <img class="logo" src="https://upload.wikimedia.org/wikipedia/commons/1/10/Sonos_2015-Logo.png"/>
    <h2 v-html="msg"></h2>
    <div class="options__container">
      <a class="option" v-on:click="meditationAction" v-bind:class="{'animated flash' : clicked}" :style="{backgroundImage: 'url(' + backgroundImage +')'}" >
        <div class="option__background-image" ></div>
        <img class="svg" :src=iconURL>
      </a>
    </div>
  </div>

Share Improve this question edited Mar 9, 2019 at 1:58 Jodast 1,2992 gold badges19 silver badges34 bronze badges asked Apr 20, 2017 at 17:06 LuccaLucca 1,5375 gold badges16 silver badges20 bronze badges 6
  • the more I look at this gif the less I understand what's going on. Please can you provide original code snippet (as text) and describe steps to repeat? what is your system keyboard layout? – lena Commented Apr 20, 2017 at 18:21
  • i've added the code snippet for the component i was working on and added a little description to further explain the content structure. I hope this helps. – Lucca Commented Apr 20, 2017 at 18:35
  • So, you had axios.get(http://localhost:5005/${this.room}/shuffle/on).then(response => { in your code, and tried to surround "localhost:5005/${this.room}/shuffle/on" with backticks? Or, tried to replace quotes with backticks? Or? What is your keyboard layout? – lena Commented Apr 21, 2017 at 14:05
  • Yes i tried to surround "localhost:5005/${this.room}/shuffle/on" with backticks. But replacing double quotes with backticks didn't work either. I am using QWERTZ keyboard layout. – Lucca Commented Apr 28, 2017 at 0:22
  • may be the youtrack.jetbrains.com/issue/WEB-21750 issue; please follow it for updates – lena Commented Apr 28, 2017 at 20:23
 |  Show 1 more comment

4 Answers 4

Reset to default 13

I have the same problem. I solved it by disabling the "Insert pair quote" option in Preferences -> Editor -> General -> Smart Keys.

Of course, it disables the inserting of pair quotes for all types of quotes, including single and double. It's a temporary workaround, but personally I'd rather actually be able to use JS's template strings despite having to type in the pair of quotes every time.

Another workaround is to write a backtick in another location and copy/paste it around the template.

Disable the insert pair quote option is a bad workaround, a better approach to deal with this is creating a live template with backticks.

Just go to Preferences -> Editor -> Live templates, create a custom template with a shortcut word (form me is tpl) containing ``, and to use this in code just type tpl+Tab key and done

Just had this "feature" (five years later) and figured out a simple solution, just hit back-tick one more time that will get the closing back-tick to stick with no preference changed in v.2022.2.3

back-tick text text back-tick back-tick

发布评论

评论列表(0)

  1. 暂无评论