Fixed tabs not kept when pasting from phpStorm

Jake B.

Well-known member
If I paste code directly from phpStorm it doesn't seem to keep the tabs in place. For example pasting the first few lines of XenForo_Application into Redactor shows this:

PHP:
<?php
if (!defined('XENFORO_AUTOLOADER_SETUP')) { die('No access.'); }
/**
* Base XenForo application class. Sets up the environment as necessary and acts as the
* registry for the application. Can broker to the autoload as well.
*
* @package XenForo_Core
*/
class XenForo_Application extends Zend_Registry
{
const URL_ID_DELIMITER = '.';
/**
* Current printable and encoded versions. These are used for visual output
* and installation/upgrading.
*
* @var string
* @var integer
*/
public static $version = '1.5.1';
public static $versionId = 1050170; // abbccde = a.b.c d (alpha: 1, beta: 3, RC: 5, stable: 7, PL: 9) e

But, if I paste it into Sublime, then copy and paste it again it behaves properly like this:
PHP:
<?php

if (!defined('XENFORO_AUTOLOADER_SETUP')) { die('No access.'); }

/**
* Base XenForo application class. Sets up the environment as necessary and acts as the
* registry for the application. Can broker to the autoload as well.
*
* @package XenForo_Core
*/
class XenForo_Application extends Zend_Registry
{
    const URL_ID_DELIMITER = '.';

    /**
    * Current printable and encoded versions. These are used for visual output
    * and installation/upgrading.
    *
    * @var string
    * @var integer
    */
    public static $version = '1.5.1';
    public static $versionId = 1050170; // abbccde = a.b.c d (alpha: 1, beta: 3, RC: 5, stable: 7, PL: 9) e

This has been driving me crazy for quite some time now :p
 
I'm not going to immediately close this as a duplicate but it is likely the same as this:

https://xenforo.com/community/threads/redactor-is-no-longer-maintaining-tabs.54615/

There is a workaround of course. Certainly in Chrome you can right click and "Paste plain text" which is what I always do and this maintains the tabs.

You can also paste it into the Insert Code editor overlay and this will also maintain the tabs.

With all this in mind I don't think we can do much more.
 
Here's what I get with the 'insert code' overlay:

PHP:
<?php

if (!defined('XENFORO_AUTOLOADER_SETUP')) { die('No access.'); }

/**
* Base XenForo application class. Sets up the environment as necessary and acts as the
* registry for the application. Can broker to the autoload as well.
*
* @package XenForo_Core
*/
class XenForo_Application extends Zend_Registry
{
const URL_ID_DELIMITER = '.';

/**
* Current printable and encoded versions. These are used for visual output
* and installation/upgrading.
*
* @var string
* @var integer
*/
public static $version = '1.5.1';
public static $versionId = 1050170; // abbccde = a.b.c d (alpha: 1, beta: 3, RC: 5, stable: 7, PL: 9) e

and with 'Paste and Match Style' (the only option it gives on right click other than just 'paste') it seems to work in redactor:
PHP:
<?php

if (!defined('XENFORO_AUTOLOADER_SETUP')) { die('No access.'); }

/**
* Base XenForo application class. Sets up the environment as necessary and acts as the
* registry for the application. Can broker to the autoload as well.
*
* @package XenForo_Core
*/
class XenForo_Application extends Zend_Registry
{
    const URL_ID_DELIMITER = '.';

    /**
    * Current printable and encoded versions. These are used for visual output
    * and installation/upgrading.
    *
    * @var string
    * @var integer
    */
    public static $version = '1.5.1';
    public static $versionId = 1050170; // abbccde = a.b.c d (alpha: 1, beta: 3, RC: 5, stable: 7, PL: 9) e
 
The code overlay works for me, though I never use that as the Paste and match style trick works for me as a workaround.
 
Thanks for the response though, much less hassle than having to open Sublime any time I want to paste something from phpStorm :)
 
@Jake B. Are you on a mac or pc? I'm a pc and my pasting from phpStorm works fine:

PHP:
public static function parseQueryString($string)
    {
        parse_str($string, $output);
        if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
        {
            self::undoMagicQuotes($output);
        }

        return $output;
    }

Might be a setting (you can have the tabbing actually be spaces or other white space options).
 
@Jake B. Are you on a mac or pc? I'm a pc and my pasting from phpStorm works fine:

PHP:
public static function parseQueryString($string)
    {
        parse_str($string, $output);
        if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
        {
            self::undoMagicQuotes($output);
        }

        return $output;
    }

Might be a setting (you can have the tabbing actually be spaces or other white space options).

OS X 10.11. For PHP I have my tabs set as actual tabs, but it does the same thing with Ruby when I have tabs set as spaces :\

Code:
module Admin
class FaqController < AdminController
before_action :set_faq, only: [:show, :edit, :update, :destroy]
end
end

But apparently @Chris D had this issue before, and it isn't something they can fix
 
Mike is going to take another look at it but there's definite similarities between the issues. Hopefully we'll come up with something :)
 
I have managed to improve this, though the way the HTML gets exposed is a little strange:
  1. Tabs actually come in as 3 spaces.
  2. Leading tabs (white space?) that is equal between all lines is automatically and silently removed (so there will always be a character at column 1).
Regardless, I have fixed this and another bug where blank lines in the pasted output would be removed (not rolled out here yet but it will be soon).
 
Top Bottom