Preserve the scroll position in styleAdd when saving
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Jun 2020 08:32:35 +0000 (10:32 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Jun 2020 08:33:16 +0000 (10:33 +0200)
Closes #3266

wcfsetup/install/files/acp/templates/styleAdd.tpl
wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php

index 93b8f8b8ee0940702591a6c6df339da2da6d5b78..a80ad128d5ac4b4247d4658e0f1becdc7fc2f80b 100644 (file)
                                                        <dd>
                                                                <div dir="ltr">
                                                                        <textarea id="individualScssCustom" rows="20" cols="40" name="individualScssCustom">{$variables[individualScssCustom]}</textarea>
+                                                                       <input class="codeMirrorScrollOffset" name="scrollOffsets[individualScssCustom]" value="{if $scrollOffsets[individualScssCustom]|isset}{$scrollOffsets[individualScssCustom]}{else}0{/if}" type="hidden">
                                                                </div>
                                                                <small>{lang}wcf.acp.style.advanced.individualScss.description{/lang}</small>
                                                        </dd>
                                                        <dd>
                                                                <div dir="ltr">
                                                                        <textarea id="overrideScssCustom" rows="20" cols="40" name="overrideScssCustom">{$variables[overrideScssCustom]}</textarea>
+                                                                       <input class="codeMirrorScrollOffset" name="scrollOffsets[overrideScssCustom]" value="{if $scrollOffsets[overrideScssCustom]|isset}{$scrollOffsets[overrideScssCustom]}{else}0{/if}" type="hidden">
                                                                </div>
                                                                {if $errorField == 'overrideScssCustom'}
                                                                        <small class="innerError">
                                        <dd>
                                                <div dir="ltr">
                                                        <textarea id="individualScss" rows="20" cols="40" name="individualScss">{$variables[individualScss]}</textarea>
+                                                       <input class="codeMirrorScrollOffset" name="scrollOffsets[individualScss]" value="{if $scrollOffsets[individualScss]|isset}{$scrollOffsets[individualScss]}{else}0{/if}" type="hidden">
                                                </div>
                                                <small>{lang}wcf.acp.style.advanced.individualScss.description{/lang}</small>
                                        </dd>
                                        <dd>
                                                <div dir="ltr">
                                                        <textarea id="overrideScss" rows="20" cols="40" name="overrideScss">{$variables[overrideScss]}</textarea>
+                                                       <input class="codeMirrorScrollOffset" name="scrollOffsets[overrideScss]" value="{if $scrollOffsets[overrideScss]|isset}{$scrollOffsets[overrideScss]}{else}0{/if}" type="hidden">
                                                </div>
                                                {if $errorField == 'overrideScss'}
                                                        <small class="innerError">
index 15ffa0d0494b1e106f329098bd7730355fd15f66..b26656fb43d772019370b615e8cb96b262cf0330 100644 (file)
@@ -12,6 +12,7 @@ use wcf\system\exception\UserInputException;
 use wcf\system\language\I18nHandler;
 use wcf\system\Regex;
 use wcf\system\WCF;
+use wcf\util\ArrayUtil;
 use wcf\util\DateUtil;
 use wcf\util\FileUtil;
 use wcf\util\StringUtil;
@@ -199,6 +200,12 @@ class StyleAddForm extends AbstractForm {
         */
        public $specialVariables = [];
        
+       /**
+        * current scroll offsets before submitting the form
+        * @var integer[]
+        */
+       public $scrollOffsets = [];
+       
        /**
         * @inheritDoc
         */
@@ -281,6 +288,9 @@ class StyleAddForm extends AbstractForm {
                if (isset($_POST['styleVersion'])) $this->styleVersion = StringUtil::trim($_POST['styleVersion']);
                if (isset($_POST['templateGroupID'])) $this->templateGroupID = intval($_POST['templateGroupID']);
                if (isset($_POST['apiVersion']) && in_array($_POST['apiVersion'], Style::$supportedApiVersions)) $this->apiVersion = $_POST['apiVersion'];
+               
+               // codemirror scroll offset
+               if (isset($_POST['scrollOffsets']) && is_array($_POST['scrollOffsets'])) $this->scrollOffsets = ArrayUtil::toIntegerArray($_POST['scrollOffsets']); 
        }
        
        /**
@@ -652,7 +662,8 @@ class StyleAddForm extends AbstractForm {
                        'tmpHash' => $this->tmpHash,
                        'variables' => $this->variables,
                        'supportedApiVersions' => Style::$supportedApiVersions,
-                       'newVariables' => $this->newVariables
+                       'newVariables' => $this->newVariables,
+                       'scrollOffsets' => $this->scrollOffsets,
                ]);
        }